From f2e718565db931a26dd545642d570adccbeb1536 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 16 Apr 2024 16:25:55 +0200 Subject: [PATCH] Add EmailOut components: entity, DTO, repository, and services - Introduced EmailOut and EmailOutDto for data management. - Added EmailOutRepository and service interfaces based on CRUD patterns. --- .../Contracts/IEmailOutService.cs | 11 +++ .../DTOs/EmailOutDto.cs | 25 ++++++ .../MappingProfiles/BasicDtoMappingProfile.cs | 2 + .../Services/EmailOutService.cs | 17 ++++ EnvelopeGenerator.Domain/Entities/EmailOut.cs | 89 +++++++++++++++++++ .../Contracts/IEmailOutRepository.cs | 9 ++ .../Repositories/EmailOutRepository.cs | 14 +++ .../Controllers/HomeController.cs | 7 +- EnvelopeGenerator.Web/Program.cs | 2 + 9 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 EnvelopeGenerator.Application/Contracts/IEmailOutService.cs create mode 100644 EnvelopeGenerator.Application/DTOs/EmailOutDto.cs create mode 100644 EnvelopeGenerator.Application/Services/EmailOutService.cs create mode 100644 EnvelopeGenerator.Domain/Entities/EmailOut.cs create mode 100644 EnvelopeGenerator.Infrastructure/Contracts/IEmailOutRepository.cs create mode 100644 EnvelopeGenerator.Infrastructure/Repositories/EmailOutRepository.cs diff --git a/EnvelopeGenerator.Application/Contracts/IEmailOutService.cs b/EnvelopeGenerator.Application/Contracts/IEmailOutService.cs new file mode 100644 index 00000000..e1f934b5 --- /dev/null +++ b/EnvelopeGenerator.Application/Contracts/IEmailOutService.cs @@ -0,0 +1,11 @@ +using DigitalData.Core.Contracts.Application; +using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Domain.Entities; +using EnvelopeGenerator.Infrastructure.Contracts; + +namespace EnvelopeGenerator.Application.Contracts +{ + public interface IEmailOutService : IBasicCRUDService + { + } +} diff --git a/EnvelopeGenerator.Application/DTOs/EmailOutDto.cs b/EnvelopeGenerator.Application/DTOs/EmailOutDto.cs new file mode 100644 index 00000000..6455acf7 --- /dev/null +++ b/EnvelopeGenerator.Application/DTOs/EmailOutDto.cs @@ -0,0 +1,25 @@ +namespace EnvelopeGenerator.Application.DTOs +{ + public record EmailOutDto( + int Guid, + int ReminderTypeId, + int SendingProfile, + int ReferenceId, + string? ReferenceString, + int? EntityId, + int WfId, + string? WfReference, + string EmailAdress, + string EmailSubj, + string EmailBody, + string? EmailAttmt1, + DateTime? EmailSent, + string? Comment, + string AddedWho, + DateTime? AddedWhen, + string? ChangedWho, + DateTime? ChangedWhen, + DateTime? ErrorTimestamp, + string? ErrorMsg + ); +} diff --git a/EnvelopeGenerator.Application/MappingProfiles/BasicDtoMappingProfile.cs b/EnvelopeGenerator.Application/MappingProfiles/BasicDtoMappingProfile.cs index 3dbe14a5..cd7304f7 100644 --- a/EnvelopeGenerator.Application/MappingProfiles/BasicDtoMappingProfile.cs +++ b/EnvelopeGenerator.Application/MappingProfiles/BasicDtoMappingProfile.cs @@ -21,6 +21,7 @@ namespace EnvelopeGenerator.Application.MappingProfiles CreateMap(); CreateMap(); CreateMap(); + CreateMap(); // DTO to Entity mappings CreateMap(); @@ -35,6 +36,7 @@ namespace EnvelopeGenerator.Application.MappingProfiles CreateMap(); CreateMap(); CreateMap(); + CreateMap(); } } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Services/EmailOutService.cs b/EnvelopeGenerator.Application/Services/EmailOutService.cs new file mode 100644 index 00000000..e022f369 --- /dev/null +++ b/EnvelopeGenerator.Application/Services/EmailOutService.cs @@ -0,0 +1,17 @@ +using AutoMapper; +using DigitalData.Core.Application; +using DigitalData.Core.Contracts.CultureServices; +using EnvelopeGenerator.Application.Contracts; +using EnvelopeGenerator.Application.DTOs; +using EnvelopeGenerator.Domain.Entities; +using EnvelopeGenerator.Infrastructure.Contracts; + +namespace EnvelopeGenerator.Application.Services +{ + public class EmailOutService : BasicCRUDService, IEmailOutService + { + public EmailOutService(IEmailOutRepository repository, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper) + { + } + } +} diff --git a/EnvelopeGenerator.Domain/Entities/EmailOut.cs b/EnvelopeGenerator.Domain/Entities/EmailOut.cs new file mode 100644 index 00000000..68ac00b1 --- /dev/null +++ b/EnvelopeGenerator.Domain/Entities/EmailOut.cs @@ -0,0 +1,89 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace EnvelopeGenerator.Domain.Entities +{ + [Table("TBEMLP_EMAIL_OUT", Schema = "dbo")] + public class EmailOut + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("GUID")] + public int Id { get; set; } + + [Required] + [Column("REMINDER_TYPE_ID")] + public int ReminderTypeId { get; set; } = 1; // Default value + + [Required] + [Column("SENDING_PROFILE")] + public int SendingProfile { get; set; } + + [Required] + [Column("REFERENCE_ID")] + public int ReferenceId { get; set; } + + [StringLength(200)] + [Column("REFERENCE_STRING")] + public string ReferenceString { get; set; } + + [Column("ENTITY_ID")] + public int? EntityId { get; set; } + + [Required] + [Column("WF_ID")] + public int WfId { get; set; } + + [StringLength(200)] + [Column("WF_REFERENCE")] + public string WfReference { get; set; } + + [Required] + [StringLength(1000)] + [Column("EMAIL_ADRESS")] + public string EmailAdress { get; set; } + + [Required] + [StringLength(500)] + [Column("EMAIL_SUBJ")] + public string EmailSubj { get; set; } + + [Required] + [Column("EMAIL_BODY")] + public string EmailBody { get; set; } + + [StringLength(512)] + [Column("EMAIL_ATTMT1")] + public string EmailAttmt1 { get; set; } + + [Column("EMAIL_SENT")] + public DateTime? EmailSent { get; set; } + + [StringLength(500)] + [Column("COMMENT")] + public string Comment { get; set; } + + [Required] + [StringLength(50)] + [Column("ADDED_WHO")] + public string AddedWho { get; set; } = "DEFAULT"; // Default value + + [Column("ADDED_WHEN")] + public DateTime? AddedWhen { get; set; } = DateTime.Now; // Default value + + [StringLength(50)] + [Column("CHANGED_WHO")] + public string ChangedWho { get; set; } + + [Column("CHANGED_WHEN")] + public DateTime? ChangedWhen { get; set; } + + [Column("ERROR_TIMESTAMP")] + public DateTime? ErrorTimestamp { get; set; } + + [StringLength(900)] + [Column("ERROR_MSG")] + public string ErrorMsg { get; set; } + } +} \ No newline at end of file diff --git a/EnvelopeGenerator.Infrastructure/Contracts/IEmailOutRepository.cs b/EnvelopeGenerator.Infrastructure/Contracts/IEmailOutRepository.cs new file mode 100644 index 00000000..1b7425f5 --- /dev/null +++ b/EnvelopeGenerator.Infrastructure/Contracts/IEmailOutRepository.cs @@ -0,0 +1,9 @@ +using DigitalData.Core.Contracts.Infrastructure; +using EnvelopeGenerator.Domain.Entities; + +namespace EnvelopeGenerator.Infrastructure.Contracts +{ + public interface IEmailOutRepository : ICRUDRepository + { + } +} diff --git a/EnvelopeGenerator.Infrastructure/Repositories/EmailOutRepository.cs b/EnvelopeGenerator.Infrastructure/Repositories/EmailOutRepository.cs new file mode 100644 index 00000000..397e8b14 --- /dev/null +++ b/EnvelopeGenerator.Infrastructure/Repositories/EmailOutRepository.cs @@ -0,0 +1,14 @@ +using DigitalData.Core.Infrastructure; +using DigitalData.UserManager.Infrastructure.Repositories; +using EnvelopeGenerator.Domain.Entities; +using EnvelopeGenerator.Infrastructure.Contracts; + +namespace EnvelopeGenerator.Infrastructure.Repositories +{ + public class EmailOutRepository : CRUDRepository, IEmailOutRepository + { + public EmailOutRepository(EGDbContext dbContext) : base(dbContext) + { + } + } +} diff --git a/EnvelopeGenerator.Web/Controllers/HomeController.cs b/EnvelopeGenerator.Web/Controllers/HomeController.cs index d219e671..5c4426bc 100644 --- a/EnvelopeGenerator.Web/Controllers/HomeController.cs +++ b/EnvelopeGenerator.Web/Controllers/HomeController.cs @@ -38,7 +38,7 @@ namespace EnvelopeGenerator.Web.Controllers { try { - var passwordFromConfig = _config["Config:AdminPassword"] ?? throw new InvalidOperationException("No admin password configured!"); + var passwordFromConfig = _config["Config:AdminPassword"]; if (passwordFromConfig == null) { @@ -56,8 +56,9 @@ namespace EnvelopeGenerator.Web.Controllers return View(envelopes); } - catch (Exception e) + catch(Exception ex) { + _logger.LogError(ex, "Unexpected error"); ViewData["error"] = "Unknown error!"; return View("Index"); } @@ -66,6 +67,8 @@ namespace EnvelopeGenerator.Web.Controllers [HttpGet("/EnvelopeKey/{envelopeReceiverId}")] public async Task SendAccessCode([FromRoute] string envelopeReceiverId) { + var envelope = await _envelopeService.ReadByUuidAsync(envelopeReceiverId.GetEnvelopeUuid()); + EnvelopeResponse response = await envelopeOldService.LoadEnvelope(envelopeReceiverId); if (response.Envelope.UseAccessCode) diff --git a/EnvelopeGenerator.Web/Program.cs b/EnvelopeGenerator.Web/Program.cs index 99d3236e..c254425b 100644 --- a/EnvelopeGenerator.Web/Program.cs +++ b/EnvelopeGenerator.Web/Program.cs @@ -67,6 +67,7 @@ try builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -81,6 +82,7 @@ try builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); //Auto mapping profiles builder.Services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly);