131 lines
3.0 KiB
C#
131 lines
3.0 KiB
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using EnvelopeGenerator.Domain;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnvelopeGenerator.Application.Histories.Commands;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public record CreateHistoryCommand : IRequest<long?>
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int EnvelopeId { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string UserReference { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Constants.EnvelopeStatus Status { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public DateTime AddedWhen { get; } = DateTime.Now;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public DateTime ActionDate => AddedWhen;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public string? Comment { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public EnvelopeQuery? Envelope { get; init; }
|
|
|
|
/// <summary>
|
|
/// /
|
|
/// </summary>
|
|
public ReceiverQuery? Receiver { get; init; }
|
|
}
|
|
|
|
#region Queries
|
|
/// <summary>
|
|
/// Repräsentiert eine Abfrage für Umschläge.
|
|
/// </summary>
|
|
public record EnvelopeQuery
|
|
{
|
|
/// <summary>
|
|
/// Die eindeutige Kennung des Umschlags.
|
|
/// </summary>
|
|
public int? Id { get; init; }
|
|
|
|
/// <summary>
|
|
/// Die universell eindeutige Kennung des Umschlags.
|
|
/// </summary>
|
|
public string? Uuid { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stellt eine Abfrage dar, um die Details eines Empfängers zu lesen.
|
|
/// um spezifische Informationen über einen Empfänger abzurufen.
|
|
/// </summary>
|
|
public record ReceiverQuery
|
|
{
|
|
/// <summary>
|
|
/// ID des Empfängers
|
|
/// </summary>
|
|
public int? Id { get; init; }
|
|
|
|
/// <summary>
|
|
/// E-Mail Adresse des Empfängers
|
|
/// </summary>
|
|
public string? EmailAddress { get; init; }
|
|
|
|
/// <summary>
|
|
/// Eindeutige Signatur des Empfängers
|
|
/// </summary>
|
|
public string? Signature { get; set; }
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class CreateHistoryCommandHandler : IRequestHandler<CreateHistoryCommand, long?>
|
|
{
|
|
private readonly IRepository<EnvelopeHistory> _repo;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repo"></param>
|
|
public CreateHistoryCommandHandler(IRepository<EnvelopeHistory> repo)
|
|
{
|
|
_repo = repo;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public async Task<long?> Handle(CreateHistoryCommand request, CancellationToken cancel)
|
|
{
|
|
// create entitiy
|
|
await _repo.CreateAsync(request, cancel);
|
|
|
|
// check if created
|
|
var record = await _repo.ReadOnly()
|
|
.Where(h => h.EnvelopeId == request.EnvelopeId)
|
|
.Where(h => h.UserReference == request.UserReference)
|
|
.Where(h => h.ActionDate == request.ActionDate)
|
|
.SingleOrDefaultAsync(cancel);
|
|
|
|
return record?.Id;
|
|
}
|
|
} |