diff --git a/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs b/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs
index bddc7a52..25ed293e 100644
--- a/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs
+++ b/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs
@@ -1,37 +1,56 @@
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using DigitalData.Core.Exceptions;
-using MediatR;
-using System.Text.Json.Serialization;
-using EnvelopeGenerator.Domain.Entities;
-using Microsoft.EntityFrameworkCore;
using EnvelopeGenerator.Domain.Constants;
-using EnvelopeGenerator.Application.Common.Dto;
+using EnvelopeGenerator.Domain.Entities;
+using MediatR;
+using System.Linq.Expressions;
-namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Update;
+namespace EnvelopeGenerator.Application.EmailTemplates.Commands;
+
+///
+///
+///
+///
+///
+public record EmailTemplateUpdateDto(string Body, string Subject);
///
/// Befehl zum Aktualisieren einer E-Mail-Vorlage.
///
-///
-/// (Optional)Der neue Inhalt des E-Mail-Textkörpers. Wenn null, bleibt der vorhandene Inhalt unverändert.
-///
-///
-/// (Optional) Der neue Betreff der E-Mail. Wenn null, bleibt der vorhandene Betreff unverändert.
-///
-public record UpdateEmailTemplateCommand(string? Body = null, string? Subject = null) : IRequest
+public record UpdateEmailTemplateCommand : IEmailTemplateQuery, IRequest
{
- ///
- /// Die Abfrage, die die E-Mail-Vorlage darstellt, die aktualisiert werden soll.
- ///
- [JsonIgnore]
- public IEmailTemplateQuery? EmailTemplateQuery { get; set; }
+ ///
+ /// Die eindeutige Kennung der E-Mail-Vorlage (optional).
+ ///
+ public int? Id { get; set; }
+
+ ///
+ /// Der Typ der E-Mail-Vorlage, z. B. (optional). Beispiele:
+ /// 0 - DocumentReceived: Benachrichtigung über den Empfang eines Dokuments.
+ /// 1 - DocumentSigned: Benachrichtigung über die Unterzeichnung eines Dokuments.
+ /// 2 - DocumentDeleted: Benachrichtigung über das Löschen eines Dokuments.
+ /// 3 - DocumentCompleted: Benachrichtigung über den Abschluss eines Dokuments.
+ /// 4 - DocumentAccessCodeReceived: Benachrichtigung über den Erhalt eines Zugangscodes.
+ /// 5 - DocumentShared: Benachrichtigung über das Teilen eines Dokuments.
+ /// 6 - TotpSecret: Benachrichtigung über ein TOTP-Geheimnis.
+ /// 7 - DocumentRejected_ADM (für den Absender): Mail an den Absender, wenn das Dokument abgelehnt wird.
+ /// 8 - DocumentRejected_REC (für den ablehnenden Empfänger): Mail an den ablehnenden Empfänger, wenn das Dokument abgelehnt wird.
+ /// 9 - DocumentRejected_REC_2 (für sonstige Empfänger): Mail an andere Empfänger (Brief), wenn das Dokument abgelehnt wird.
+ ///
+ public EmailTemplateType? Type { get; set; }
///
///
///
- [JsonIgnore]
- public DateTime ChangedWhen { get; init; } = DateTime.Now;
+ public Expression> QueryExpression => Id is int id
+ ? temp => temp.Id == id
+ : temp => temp!.Name == Type.ToString();
+
+ ///
+ /// Die aktualisierte E-Mail-Vorlage.
+ ///
+ public EmailTemplateUpdateDto Update { get; init; } = null!;
}
///
@@ -41,17 +60,13 @@ public class UpdateEmailTemplateCommandHandler : IRequestHandler _repository;
- private readonly IMapper _mapper;
-
///
///
///
///
- ///
- public UpdateEmailTemplateCommandHandler(IRepository repository, IMapper mapper)
+ public UpdateEmailTemplateCommandHandler(IRepository repository)
{
_repository = repository;
- _mapper = mapper;
}
///
@@ -62,31 +77,6 @@ public class UpdateEmailTemplateCommandHandler : IRequestHandler
///
///
- [Obsolete("Use Read-method returning IReadQuery instead.")]
- public async Task Handle(UpdateEmailTemplateCommand request, CancellationToken cancel)
- {
- EmailTemplateDto? tempDto;
-
- if (request.EmailTemplateQuery?.Id is int id)
- {
- var temp = await _repository.ReadOnly().Where(t => t.Id == id).FirstOrDefaultAsync(cancel);
- tempDto = _mapper.Map(temp);
- }
- else if (request!.EmailTemplateQuery!.Type is EmailTemplateType type)
- {
- var temp = await _repository.ReadOnly().Where(t => t.Name == type.ToString()).FirstOrDefaultAsync(cancel);
- tempDto = _mapper.Map(temp);
- }
- else
- {
- throw new InvalidOperationException("Both id and type is null. Id: " + request.EmailTemplateQuery.Id + ". Type: " + request.EmailTemplateQuery.Type.ToString());
- }
-
- if (tempDto == null)
- {
- throw new NotFoundException();
- }
-
- await _repository.UpdateAsync(tempDto, t => t.Id == tempDto.Id, cancel);
- }
+ public Task Handle(UpdateEmailTemplateCommand request, CancellationToken cancel)
+ => _repository.UpdateAsync(request.Update, request.QueryExpression, cancel);
}
\ No newline at end of file
diff --git a/EnvelopeGenerator.Application/EmailTemplates/MappingProfile.cs b/EnvelopeGenerator.Application/EmailTemplates/MappingProfile.cs
index e6cba17d..bf19ddb0 100644
--- a/EnvelopeGenerator.Application/EmailTemplates/MappingProfile.cs
+++ b/EnvelopeGenerator.Application/EmailTemplates/MappingProfile.cs
@@ -17,8 +17,7 @@ public class MappingProfile : Profile
{
CreateMap();
- CreateMap()
- .ForMember(dest => dest.Id, opt => opt.Ignore())
- .ForMember(dest => dest.ChangedWhen, opt => opt.MapFrom(_ => DateTime.Now));
+ CreateMap()
+ .ForMember(dest => dest.ChangedWhen, opt => opt.MapFrom(_ => DateTime.UtcNow));
}
}
\ No newline at end of file