Integrated `PdfSignatureService` to enable fetching and previewing signed PDFs for completed envelopes. Updated `SenderPage.razor` to dynamically adjust popup headers and filenames based on the envelope's status. Enhanced `OpenPreviewAsync` to conditionally fetch signed or original PDFs. Registered `PdfSignatureService` and DevExpress PDF Viewer in `Program.cs`. Implemented `PdfSignatureService` to handle API calls for retrieving signed PDFs with error handling.
25 lines
950 B
C#
25 lines
950 B
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
|
|
namespace EnvelopeGenerator.Server.Client.Services;
|
|
|
|
public class PdfSignatureService(IHttpClientFactory httpClientFactory)
|
|
{
|
|
/// <summary>
|
|
/// Calls POST /api/PdfSignature with the envelope id and returns the fully signed PDF bytes.
|
|
/// </summary>
|
|
public async Task<byte[]> GetSignedPdfAsync(int envelopeId, CancellationToken cancel = default)
|
|
{
|
|
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
|
var response = await http.PostAsJsonAsync("/api/PdfSignature", new { Id = envelopeId }, cancel);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
throw new HttpRequestException(
|
|
$"Failed to load signed PDF. Status: {(int)response.StatusCode} ({response.ReasonPhrase ?? "Unknown"})",
|
|
null,
|
|
response.StatusCode);
|
|
|
|
return await response.Content.ReadAsByteArrayAsync(cancel);
|
|
}
|
|
}
|