Simplify payload handling in UpsertAsync method

Refactored the `UpsertAsync` method in `EnvelopeService` to remove
manual construction of the HTTP POST payload. The method now
directly uses the `CreateEnvelopeCommand` object as the payload
for the `PostAsJsonAsync` call. This change reduces redundancy,
simplifies the code, and leverages the existing object structure
for better maintainability.
This commit is contained in:
2026-10-01 15:53:10 +02:00
parent 3b5075fe44
commit 123889451f

View File

@@ -101,26 +101,7 @@ public class EnvelopeService(IHttpClientFactory clientFactory)
CancellationToken cancel = default) CancellationToken cancel = default)
{ {
var httpClient = clientFactory.CreateClient("EnvelopeGenerator.Server"); var httpClient = clientFactory.CreateClient("EnvelopeGenerator.Server");
var payload = new var response = await httpClient.PostAsJsonAsync("/api/Envelope", request, _jsonOptions, cancel);
{
EnvelopeId = request.EnvelopeId,
Title = request.Title,
Message = request.Message,
TFAEnabled = request.TFAEnabled,
Send = request.Send,
Document = request.Document is null
? null
: new { DataAsBase64 = request.Document.DataAsBase64 },
Receivers = request.Receivers.Select(r => new
{
EmailAddress = r.EmailAddress,
Name = r.Name,
PhoneNumber = r.PhoneNumber,
Fields = r.Fields.Select(f => new { X = f.X, Y = f.Y, Page = f.Page }).ToList()
}).ToList()
};
var response = await httpClient.PostAsJsonAsync("/api/Envelope", payload, _jsonOptions, cancel);
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<EnvelopeDto>(_jsonOptions, cancel); return await response.Content.ReadFromJsonAsync<EnvelopeDto>(_jsonOptions, cancel);