diff --git a/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs b/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs index 25ed293e..71421a68 100644 --- a/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs +++ b/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs @@ -1,9 +1,7 @@ -using AutoMapper; -using DigitalData.Core.Abstraction.Application.Repository; -using DigitalData.Core.Exceptions; +using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Application.Common.Commands; using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Domain.Entities; -using MediatR; using System.Linq.Expressions; namespace EnvelopeGenerator.Application.EmailTemplates.Commands; @@ -18,7 +16,7 @@ public record EmailTemplateUpdateDto(string Body, string Subject); /// /// Befehl zum Aktualisieren einer E-Mail-Vorlage. /// -public record UpdateEmailTemplateCommand : IEmailTemplateQuery, IRequest +public record UpdateEmailTemplateCommand : UpdateCommand, IEmailTemplateQuery { /// /// Die eindeutige Kennung der E-Mail-Vorlage (optional). @@ -43,40 +41,23 @@ public record UpdateEmailTemplateCommand : IEmailTemplateQuery, IRequest /// /// /// - public Expression> QueryExpression => Id is int id + /// + public override Expression> BuildQueryExpression() + => Id is int id ? temp => temp.Id == id : temp => temp!.Name == Type.ToString(); - - /// - /// Die aktualisierte E-Mail-Vorlage. - /// - public EmailTemplateUpdateDto Update { get; init; } = null!; } /// /// /// -public class UpdateEmailTemplateCommandHandler : IRequestHandler +public class UpdateEmailTemplateCommandHandler : UpdateCommandHandler { - private readonly IRepository _repository; - /// /// /// /// - public UpdateEmailTemplateCommandHandler(IRepository repository) + public UpdateEmailTemplateCommandHandler(IRepository repository) : base(repository) { - _repository = repository; } - - /// - /// - /// - /// - /// - /// - /// - /// - public Task Handle(UpdateEmailTemplateCommand request, CancellationToken cancel) - => _repository.UpdateAsync(request.Update, request.QueryExpression, cancel); } \ No newline at end of file