Replaced all instances of `EnvelopeTypeId` (int/int?) with `Type` (EnvelopeType/EnvelopeType?) across the codebase to improve type safety and readability. Updated affected properties, methods, and logic in DTOs, commands, handlers, and Razor components. Introduced conditional compilation to handle differences between .NET and .NET Framework where necessary. Removed obsolete helper methods for `EnvelopeTypeId`. This refactor ensures consistent use of the strongly-typed `EnvelopeType` enum, reducing the risk of invalid values and aligning with best practices.
65 lines
2.0 KiB
C#
65 lines
2.0 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,
|
|
int FinalEmailToCreator,
|
|
int 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);
|