diff --git a/EnvelopeGenerator.Application/Histories/Commands/CreateHistoryCommand.cs b/EnvelopeGenerator.Application/Histories/Commands/CreateHistoryCommand.cs
index ad228144..dd19e05e 100644
--- a/EnvelopeGenerator.Application/Histories/Commands/CreateHistoryCommand.cs
+++ b/EnvelopeGenerator.Application/Histories/Commands/CreateHistoryCommand.cs
@@ -1,11 +1,15 @@
-using EnvelopeGenerator.Domain;
+using DigitalData.Core.Abstraction.Application.Repository;
+using EnvelopeGenerator.Domain;
+using EnvelopeGenerator.Domain.Entities;
+using MediatR;
+using Microsoft.EntityFrameworkCore;
namespace EnvelopeGenerator.Application.Histories.Commands;
///
///
///
-public record CreateHistoryCommand
+public record CreateHistoryCommand : IRequest
{
///
///
@@ -36,4 +40,42 @@ public record CreateHistoryCommand
///
///
public string? Comment { get; set; }
+}
+
+///
+///
+///
+public class CreateHistoryCommandHandler : IRequestHandler
+{
+ private readonly IRepository _repo;
+
+ ///
+ ///
+ ///
+ ///
+ public CreateHistoryCommandHandler(IRepository repo)
+ {
+ _repo = repo;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task 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;
+ }
}
\ No newline at end of file
diff --git a/EnvelopeGenerator.Application/Histories/MappingProfile.cs b/EnvelopeGenerator.Application/Histories/MappingProfile.cs
index b1f7ca6a..8ce5c5bc 100644
--- a/EnvelopeGenerator.Application/Histories/MappingProfile.cs
+++ b/EnvelopeGenerator.Application/Histories/MappingProfile.cs
@@ -1,4 +1,5 @@
using AutoMapper;
+using EnvelopeGenerator.Application.Histories.Commands;
using EnvelopeGenerator.Application.Histories.Queries.Read;
using EnvelopeGenerator.Domain.Entities;
@@ -15,5 +16,6 @@ public class MappingProfile: Profile
public MappingProfile()
{
CreateMap();
+ CreateMap();
}
}