Replaced raw `int` values with the strongly-typed `FinalEmailType` enum for `FinalEmailToCreator` and `FinalEmailToReceivers` across the codebase. Updated DTOs, entities, commands, handlers, Razor components, and test controllers to reflect this change. This improves type safety, code readability, and maintainability. Default values now use `FinalEmailType.No` instead of integer casting. Adjusted database mappings and added necessary imports to support the new enum type.
65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using System.Text.Json;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace EnvelopeGenerator.Server.Client.Services;
|
|
|
|
public sealed class CreateEnvelopeBootstrapStorageService(IJSRuntime jsRuntime)
|
|
{
|
|
private const string StorageKeyPrefix = "sender.createEnvelope.bootstrap.";
|
|
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
|
|
|
|
public async Task<string> StoreAsync(CreateEnvelopeBootstrapPayload payload)
|
|
{
|
|
var token = Guid.NewGuid().ToString("N");
|
|
var key = BuildStorageKey(token);
|
|
var json = JsonSerializer.Serialize(payload, JsonOptions);
|
|
await jsRuntime.InvokeVoidAsync("sessionStorage.setItem", key, json);
|
|
return token;
|
|
}
|
|
|
|
public async Task<CreateEnvelopeBootstrapPayload?> ConsumeAsync(string? token)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(token))
|
|
return null;
|
|
|
|
var key = BuildStorageKey(token);
|
|
var raw = await jsRuntime.InvokeAsync<string?>("sessionStorage.getItem", key);
|
|
await jsRuntime.InvokeVoidAsync("sessionStorage.removeItem", key);
|
|
|
|
if (string.IsNullOrWhiteSpace(raw))
|
|
return null;
|
|
|
|
try
|
|
{
|
|
return JsonSerializer.Deserialize<CreateEnvelopeBootstrapPayload>(raw, JsonOptions);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static string BuildStorageKey(string token) => $"{StorageKeyPrefix}{token}";
|
|
}
|
|
|
|
public sealed record CreateEnvelopeBootstrapPayload(
|
|
string Title,
|
|
string Message,
|
|
EnvelopeType? Type,
|
|
string Language,
|
|
bool UseAccessCode,
|
|
bool TFAEnabled,
|
|
FinalEmailType FinalEmailToCreator,
|
|
FinalEmailType FinalEmailToReceivers,
|
|
bool SendReminderEmails,
|
|
int FirstReminderDays,
|
|
int ReminderIntervalDays,
|
|
int ExpiresWhenDays,
|
|
int ExpiresWarningWhenDays,
|
|
IReadOnlyList<CreateEnvelopeBootstrapReceiver> Receivers,
|
|
byte[]? DocumentBytes,
|
|
string? DocumentFileName);
|
|
|
|
public sealed record CreateEnvelopeBootstrapReceiver(string FullName, string EmailAddress);
|