- Introduce EmailTemplateUpdateDto for update payloads. - Expose Id and Type directly on UpdateEmailTemplateCommand; remove EmailTemplateQuery property. - Add QueryExpression for flexible template selection by Id or Type. - Remove AutoMapper and EmailTemplateDto usage from handler; update repository call to use EmailTemplateUpdateDto. - Update MappingProfile to map EmailTemplateUpdateDto to EmailTemplate and set ChangedWhen to DateTime.UtcNow. - Remove obsolete code and improve documentation.
82 lines
3.1 KiB
C#
82 lines
3.1 KiB
C#
using AutoMapper;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using DigitalData.Core.Exceptions;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using MediatR;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace EnvelopeGenerator.Application.EmailTemplates.Commands;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="Body"></param>
|
|
/// <param name="Subject"></param>
|
|
public record EmailTemplateUpdateDto(string Body, string Subject);
|
|
|
|
/// <summary>
|
|
/// Befehl zum Aktualisieren einer E-Mail-Vorlage.
|
|
/// </summary>
|
|
public record UpdateEmailTemplateCommand : IEmailTemplateQuery, IRequest
|
|
{
|
|
/// <summary>
|
|
/// Die eindeutige Kennung der E-Mail-Vorlage (optional).
|
|
/// </summary>
|
|
public int? Id { get; set; }
|
|
|
|
/// <summary>
|
|
/// Der Typ der E-Mail-Vorlage, z. B. <see cref="EmailTemplateType"/> (optional). Beispiele:<br/>
|
|
/// 0 - DocumentReceived: Benachrichtigung über den Empfang eines Dokuments.<br/>
|
|
/// 1 - DocumentSigned: Benachrichtigung über die Unterzeichnung eines Dokuments.<br/>
|
|
/// 2 - DocumentDeleted: Benachrichtigung über das Löschen eines Dokuments.<br/>
|
|
/// 3 - DocumentCompleted: Benachrichtigung über den Abschluss eines Dokuments.<br/>
|
|
/// 4 - DocumentAccessCodeReceived: Benachrichtigung über den Erhalt eines Zugangscodes.<br/>
|
|
/// 5 - DocumentShared: Benachrichtigung über das Teilen eines Dokuments.<br/>
|
|
/// 6 - TotpSecret: Benachrichtigung über ein TOTP-Geheimnis.<br/>
|
|
/// 7 - DocumentRejected_ADM (für den Absender): Mail an den Absender, wenn das Dokument abgelehnt wird.<br/>
|
|
/// 8 - DocumentRejected_REC (für den ablehnenden Empfänger): Mail an den ablehnenden Empfänger, wenn das Dokument abgelehnt wird.<br/>
|
|
/// 9 - DocumentRejected_REC_2 (für sonstige Empfänger): Mail an andere Empfänger (Brief), wenn das Dokument abgelehnt wird.
|
|
/// </summary>
|
|
public EmailTemplateType? Type { get; set; }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public Expression<Func<EmailTemplate, bool>> QueryExpression => Id is int id
|
|
? temp => temp.Id == id
|
|
: temp => temp!.Name == Type.ToString();
|
|
|
|
/// <summary>
|
|
/// Die aktualisierte E-Mail-Vorlage.
|
|
/// </summary>
|
|
public EmailTemplateUpdateDto Update { get; init; } = null!;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class UpdateEmailTemplateCommandHandler : IRequestHandler<UpdateEmailTemplateCommand>
|
|
{
|
|
private readonly IRepository<EmailTemplate> _repository;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
public UpdateEmailTemplateCommandHandler(IRepository<EmailTemplate> repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="InvalidOperationException"></exception>
|
|
/// <exception cref="NotFoundException"></exception>
|
|
public Task Handle(UpdateEmailTemplateCommand request, CancellationToken cancel)
|
|
=> _repository.UpdateAsync(request.Update, request.QueryExpression, cancel);
|
|
} |