diff --git a/EnvelopeGenerator.Application/Configurations/DispatcherConfig.cs b/EnvelopeGenerator.Application/Configurations/DispatcherConfig.cs new file mode 100644 index 00000000..7e261241 --- /dev/null +++ b/EnvelopeGenerator.Application/Configurations/DispatcherConfig.cs @@ -0,0 +1,13 @@ +namespace EnvelopeGenerator.Application.Configurations +{ + public class DispatcherConfig + { + public int SendingProfile { get; init; } = 1; + + public string AddedWho { get; init; } = "DDEnvelopGenerator"; + + public int ReminderTypeId { get; init; } = 202377; + + public string EmailAttmt1 { get; init; } = string.Empty; + } +} \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Configurations/MailConfig.cs b/EnvelopeGenerator.Application/Configurations/MailConfig.cs new file mode 100644 index 00000000..885d0cca --- /dev/null +++ b/EnvelopeGenerator.Application/Configurations/MailConfig.cs @@ -0,0 +1,7 @@ +namespace EnvelopeGenerator.Application.Configurations +{ + public class MailConfig + { + public required Dictionary Placeholders { get; init; } = new(); + } +} \ No newline at end of file diff --git a/EnvelopeGenerator.Application/DIExtensions.cs b/EnvelopeGenerator.Application/DIExtensions.cs index 80db37ba..1fcd6bc8 100644 --- a/EnvelopeGenerator.Application/DIExtensions.cs +++ b/EnvelopeGenerator.Application/DIExtensions.cs @@ -1,16 +1,18 @@ using DigitalData.UserManager.Application.MappingProfiles; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.MappingProfiles; +using EnvelopeGenerator.Application.Configurations; using EnvelopeGenerator.Application.Services; using EnvelopeGenerator.Infrastructure.Contracts; using EnvelopeGenerator.Infrastructure.Repositories; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace EnvelopeGenerator.Application { public static class DIExtensions { - public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services) + public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfigurationSection dispatcherConfigSection, IConfigurationSection mailConfigSection) { //Inject CRUD Service and repositoriesad services.AddScoped(); @@ -48,7 +50,15 @@ namespace EnvelopeGenerator.Application services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly); services.AddAutoMapper(typeof(UserMappingProfile).Assembly); + services.Configure(dispatcherConfigSection); + services.Configure(mailConfigSection); + //services.Configure(mailConfig.GetSection(typeof(MailConfig).ToString())); + //IConfigurationSection section = builder.Configuration.GetSection(typeof(T).Name); return services; } + + public static IServiceCollection AddEnvelopeGenerator(this IServiceCollection services, IConfiguration config) => services.AddEnvelopeGenerator( + dispatcherConfigSection: config.GetSection(typeof(DispatcherConfig).ToString()), + mailConfigSection: config.GetSection(typeof(MailConfig).ToString())); } -} +} \ No newline at end of file diff --git a/EnvelopeGenerator.Application/DispatcherConfig.cs b/EnvelopeGenerator.Application/DispatcherConfig.cs deleted file mode 100644 index 036ff8a2..00000000 --- a/EnvelopeGenerator.Application/DispatcherConfig.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace EnvelopeGenerator.Application -{ - public class DispatcherConfig - { - public int SendingProfile { get; init; } = 1; - - public string AddedWho { get; init; } = "DDEnvelopGenerator"; - - public int ReminderTypeId { get; init; } = 202377; - - public string EmailAttmt1 { get; init; } = string.Empty; - } -} \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Services/EnvelopeMailService.cs b/EnvelopeGenerator.Application/Services/EnvelopeMailService.cs index fad38655..5e6ca13e 100644 --- a/EnvelopeGenerator.Application/Services/EnvelopeMailService.cs +++ b/EnvelopeGenerator.Application/Services/EnvelopeMailService.cs @@ -3,16 +3,15 @@ using DigitalData.Core.DTO; using DigitalData.EmailProfilerDispatcher.Abstraction.Contracts; using DigitalData.EmailProfilerDispatcher.Abstraction.DTOs.EmailOut; using DigitalData.EmailProfilerDispatcher.Abstraction.Services; -using DigitalData.UserManager.Application; using EnvelopeGenerator.Application.Contracts; using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver; using EnvelopeGenerator.Common; -using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using static EnvelopeGenerator.Common.Constants; using EnvelopeGenerator.Extensions; using EnvelopeGenerator.Application.DTOs.EnvelopeReceiverReadOnly; +using EnvelopeGenerator.Application.Configurations; namespace EnvelopeGenerator.Application.Services { @@ -22,49 +21,50 @@ namespace EnvelopeGenerator.Application.Services private readonly IEnvelopeReceiverService _envRcvService; private readonly DispatcherConfig _dConfig; private readonly IConfigService _configService; + private readonly Dictionary _placeholders; - public EnvelopeMailService(IEmailOutRepository repository, IStringLocalizer localizer, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions dispatcherConfigOptions, IConfigService configService) : base(repository, mapper) + public EnvelopeMailService(IEmailOutRepository repository, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions dispatcherConfigOptions, IConfigService configService, IOptions mailConfig) : base(repository, mapper) { _tempService = tempService; _envRcvService = envelopeReceiverService; _dConfig = dispatcherConfigOptions.Value; _configService = configService; + _placeholders = mailConfig.Value.Placeholders; } - //TODO: create ioptions and implement TemplatePlaceHolderAttribute instead of this method private async Task> CreatePlaceholders(string? accessCode = null, EnvelopeReceiverDto? envelopeReceiverDto = null, EnvelopeReceiverReadOnlyDto? readOnlyDto = null) { - Dictionary placeholders = new() { - { "[NAME_PORTAL]", "signFlow" }, - { "[SIGNATURE_TYPE]" , "signieren"}, - { "[REASON]", string.Empty } }; - if (accessCode is not null) - placeholders["[DOCUMENT_ACCESS_CODE]"] = accessCode; + _placeholders["[DOCUMENT_ACCESS_CODE]"] = accessCode; if(envelopeReceiverDto?.Envelope is not null && envelopeReceiverDto.Receiver is not null) { var erId = (envelopeReceiverDto.Envelope.Uuid, envelopeReceiverDto.Receiver.Signature).EncodeEnvelopeReceiverId(); var sigHost = await _configService.ReadDefaultSignatureHost(); var linkToDoc = $"{sigHost}/EnvelopeKey/{erId}"; - placeholders["[LINK_TO_DOCUMENT]"] = linkToDoc; - placeholders["[LINK_TO_DOCUMENT_TEXT]"] = linkToDoc[..Math.Min(40, linkToDoc.Length)] + ".."; + _placeholders["[LINK_TO_DOCUMENT]"] = linkToDoc; + _placeholders["[LINK_TO_DOCUMENT_TEXT]"] = linkToDoc[..Math.Min(40, linkToDoc.Length)] + ".."; } - if(readOnlyDto?.Envelope is not null && readOnlyDto.Receiver is not null) - { - placeholders["[NAME_RECEIVER]"] = await _envRcvService.ReadLastUsedReceiverNameByMail(readOnlyDto.AddedWho).ThenAsync(res => res, (msg, ntc) => string.Empty) ?? string.Empty; + return _placeholders; + } + + private async Task> CreatePlaceholders(EnvelopeReceiverReadOnlyDto? readOnlyDto = null) + { + if (readOnlyDto?.Envelope is not null && readOnlyDto.Receiver is not null) + { + _placeholders["[NAME_RECEIVER]"] = await _envRcvService.ReadLastUsedReceiverNameByMail(readOnlyDto.AddedWho).ThenAsync(res => res, (msg, ntc) => string.Empty) ?? string.Empty; var erReadOnlyId = (readOnlyDto.Id).EncodeEnvelopeReceiverId(); var sigHost = await _configService.ReadDefaultSignatureHost(); var linkToDoc = $"{sigHost}/EnvelopeKey/{erReadOnlyId}"; - placeholders["[LINK_TO_DOCUMENT]"] = linkToDoc; - placeholders["[LINK_TO_DOCUMENT_TEXT]"] = linkToDoc[..Math.Min(40, linkToDoc.Length)] + ".."; + _placeholders["[LINK_TO_DOCUMENT]"] = linkToDoc; + _placeholders["[LINK_TO_DOCUMENT_TEXT]"] = linkToDoc[..Math.Min(40, linkToDoc.Length)] + ".."; } - return placeholders; - } + return _placeholders; + } - public async Task> SendAccessCodeAsync(EnvelopeReceiverDto dto) => await SendAsync(dto: dto, tempType: Constants.EmailTemplateType.DocumentAccessCodeReceived); + public async Task> SendAccessCodeAsync(EnvelopeReceiverDto dto) => await SendAsync(dto: dto, tempType: Constants.EmailTemplateType.DocumentAccessCodeReceived); public async Task> SendAsync(EnvelopeReceiverDto dto, Constants.EmailTemplateType tempType) { diff --git a/EnvelopeGenerator.Web/Program.cs b/EnvelopeGenerator.Web/Program.cs index 81459100..4ae334c3 100644 --- a/EnvelopeGenerator.Web/Program.cs +++ b/EnvelopeGenerator.Web/Program.cs @@ -83,7 +83,7 @@ try builder.Services.AddDbContext(options => options.UseSqlServer(connStr)); // Add envelope generator services - builder.Services.AddEnvelopeGenerator(); + builder.Services.AddEnvelopeGenerator(config); builder.Services.Configure(options => { @@ -157,8 +157,6 @@ try builder.Services.AddMemoryCache(); - builder.ConfigureBySection(); - builder.ConfigureBySection(); var app = builder.Build(); diff --git a/EnvelopeGenerator.Web/appsettings.json b/EnvelopeGenerator.Web/appsettings.json index 181159b5..484f1d6c 100644 --- a/EnvelopeGenerator.Web/appsettings.json +++ b/EnvelopeGenerator.Web/appsettings.json @@ -135,5 +135,12 @@ "Src": "/img/digital_data.svg", "ShowPageClass": "dd-show-logo", "LockedPageClass": "dd-locked-logo" + }, + "MailOptions": { + "Placeholders": { + "[NAME_PORTAL]": "signFlow", + "[SIGNATURE_TYPE]": "signieren", + "[REASON]": "" + } } } \ No newline at end of file