diff --git a/EnvelopeGenerator.Application/DTOs/EmailTemplateDto.cs b/EnvelopeGenerator.Application/DTOs/EmailTemplateDto.cs index e22a4844..fbad5c4e 100644 --- a/EnvelopeGenerator.Application/DTOs/EmailTemplateDto.cs +++ b/EnvelopeGenerator.Application/DTOs/EmailTemplateDto.cs @@ -3,10 +3,30 @@ using Microsoft.AspNetCore.Mvc; namespace EnvelopeGenerator.Application.DTOs { + /// + /// + /// [ApiExplorerSettings(IgnoreApi = true)] - public record EmailTemplateDto( - int Id, - string Name, - string Body, - string Subject) : IUnique; + public record EmailTemplateDto : IUnique + { + /// + /// + /// + public int Id{ get; init; } + + /// + /// + /// + public required string Name { get; init; } + + /// + /// + /// + public required string Body { get; init; } + + /// + /// + /// + public required string Subject { get; init; } + }; } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/EmailTemplates/Commands/Reset/ResetEnvelopeTemplateCommandHandler.cs b/EnvelopeGenerator.Application/EmailTemplates/Commands/Reset/ResetEnvelopeTemplateCommandHandler.cs index 7e5b36e3..323b751c 100644 --- a/EnvelopeGenerator.Application/EmailTemplates/Commands/Reset/ResetEnvelopeTemplateCommandHandler.cs +++ b/EnvelopeGenerator.Application/EmailTemplates/Commands/Reset/ResetEnvelopeTemplateCommandHandler.cs @@ -1,4 +1,7 @@ -using EnvelopeGenerator.Domain.Entities; +using DigitalData.Core.Abstractions.Infrastructure; +using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Application.EmailTemplates.Queries.Read; +using EnvelopeGenerator.Domain.Entities; using MediatR; namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Reset; @@ -8,22 +11,37 @@ namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Reset; /// public class ResetEnvelopeTemplateCommandHandler : IRequestHandler { + private readonly IRepository _repository; + /// /// /// - /// - /// - /// - /// - public Task Handle(ResetEnvelopeTemplateCommand request, CancellationToken cancellationToken) + /// + public ResetEnvelopeTemplateCommandHandler(IRepository repository) { - throw new NotImplementedException(); + _repository = repository; + } + + public async Task Handle(ResetEnvelopeTemplateCommand request, CancellationToken cancel) + { + var temps = request.Id is not null + ? await _repository.ReadAllAsync(t => t.Id == request.Id, cancel) + : request.Type is not null + ? await _repository.ReadAllAsync(t => t.Name == request.Type.ToString(), cancel) + : await _repository.ReadAllAsync(ct: cancel); + + foreach (var temp in temps) + { + var def = Defaults.Where(t => t.Name == temp.Name).FirstOrDefault(); + if(def is not null) + await _repository.UpdateAsync(def, t => t.Id == temp.Id, cancel); + } } /// /// /// - public static readonly IEnumerable Default = new List() + public static readonly IEnumerable Defaults = new List() { new(){ Id = 1, @@ -86,4 +104,5 @@ public class ResetEnvelopeTemplateCommandHandler : IRequestHandler