From 11db4693296a9efd2c57271ec5d83b5fa0cc10fb Mon Sep 17 00:00:00 2001 From: sofiaivv Date: Sun, 26 May 2024 06:03:38 +0400 Subject: [PATCH] =?UTF-8?q?=D1=87=D1=83=D1=82=20=D1=87=D1=83=D1=82=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD=D0=B0=D0=B4=20?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D1=8C=D0=BC=D0=B0=D0=BC=D0=B8=20(=D0=B0?= =?UTF-8?q?=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA=D1=82=D0=9C=D0=B5=D0=B9?= =?UTF-8?q?=D0=BB=D0=92=D0=BE=D1=80=D0=BA=D0=B5=D1=80=20+=20=D0=9C=D0=B5?= =?UTF-8?q?=D0=B9=D0=BB=D0=9A=D0=B8=D1=82)=20+=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D1=8B=20=D0=A0=D0=B5=D0=BF=D0=BE=D1=80=D1=82=D0=9B=D0=BE?= =?UTF-8?q?=D0=B4=D0=B6=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogicExecutor.cs | 39 ++++++++++++ .../BusinessLogics/ReportLogicGuarantor.cs | 39 ++++++++++++ .../LawCompanyBusinessLogic.csproj | 4 ++ .../MailWorker/AbstractMailWorker.cs | 59 +++++++++++++++++++ .../MailWorker/MailKitWorker.cs | 44 ++++++++++++++ .../Properties/launchSettings.json | 26 ++++---- 6 files changed, 198 insertions(+), 13 deletions(-) create mode 100644 LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicExecutor.cs create mode 100644 LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicGuarantor.cs create mode 100644 LawCompany/LawCompanyBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 LawCompany/LawCompanyBusinessLogic/MailWorker/MailKitWorker.cs diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicExecutor.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicExecutor.cs new file mode 100644 index 0000000..7efe614 --- /dev/null +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicExecutor.cs @@ -0,0 +1,39 @@ +using LawCompanyBusinessLogic.OfficePackage.HelperModels; +using LawCompanyBusinessLogic.OfficePackage; +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using LawCompanyContracts.SearchModels; +using LawCompanyContracts.StoragesContracts; +using LawCompanyContracts.ViewModels; +using LawCompanyDatabaseImplement.Models; + +namespace HotelBusinessLogic.BusinessLogics +{ + public class ReportLogicExecutor : IReportExecutorLogic + { + private readonly IHearingStorage _hearingStorage; + private readonly ILawyerStorage _lawyerStorage; + private readonly IVisitStorage _visitStorage; + private readonly IConsultationStorage _consultationStorage; + private readonly ICaseStorage _caseStorage; + private readonly AbstractSaveToExcelExecutor _saveToExcel; + private readonly AbstractSaveToWordExecutor _saveToWord; + private readonly AbstractSaveToPdfExecutor _saveToPdf; + + public ReportLogicGuarantor(IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, + IVisitStorage visitStorage, IConsultationStorage consultationStorage, ICaseStorage caseStorage, + AbstractSaveToExcelExecutor saveToExcel, AbstractSaveToWordExecutor saveToWord, AbstractSaveToPdfExecutor saveToPdf) + { + _hearingStorage = hearingStorage; + _lawyerStorage = lawyerStorage; + _visitStorage = visitStorage; + _consultationStorage = consultationStorage; + _caseStorage = caseStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + + + } +} diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicGuarantor.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicGuarantor.cs new file mode 100644 index 0000000..16a9049 --- /dev/null +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ReportLogicGuarantor.cs @@ -0,0 +1,39 @@ +using LawCompanyBusinessLogic.OfficePackage.HelperModels; +using LawCompanyBusinessLogic.OfficePackage; +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using LawCompanyContracts.SearchModels; +using LawCompanyContracts.StoragesContracts; +using LawCompanyContracts.ViewModels; +using LawCompanyDatabaseImplement.Models; + +namespace LawCompanyBusinessLogic.BusinessLogics +{ + public class ReportLogicGuarantor : IReportGuarantorLogic + { + private readonly IVisitStorage _visitStorage; + private readonly IClientStorage _clientStorage; + private readonly ICaseStorage _caseStorage; + private readonly IConsultationStorage _consultationStorage; + private readonly IHearingStorage _hearingStorage; + private readonly AbstractSaveToExcelGuarantor _saveToExcel; + private readonly AbstractSaveToWordGuarantor _saveToWord; + private readonly AbstractSaveToPdfGuarantor _saveToPdf; + + public ReportLogicOrganiser(IVisitStorage visitStorage, IClientStorage clientStorage, ICaseStorage caseStorage, + IConsultationStorage consultationStorage, IHearingStorage hearingStorage, + AbstractSaveToExcelGuarantor saveToExcel, AbstractSaveToWordGuarantor saveToWord, AbstractSaveToPdfGuarantor saveToPdf) + { + _visitStorage = visitStorage; + _clientStorage = clientStorage; + _caseStorage = caseStorage; + _consultationStorage = consultationStorage; + _hearingStorage = hearingStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + + + } +} diff --git a/LawCompany/LawCompanyBusinessLogic/LawCompanyBusinessLogic.csproj b/LawCompany/LawCompanyBusinessLogic/LawCompanyBusinessLogic.csproj index 90b8bbc..e5ba6c0 100644 --- a/LawCompany/LawCompanyBusinessLogic/LawCompanyBusinessLogic.csproj +++ b/LawCompany/LawCompanyBusinessLogic/LawCompanyBusinessLogic.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/LawCompany/LawCompanyBusinessLogic/MailWorker/AbstractMailWorker.cs b/LawCompany/LawCompanyBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..628e322 --- /dev/null +++ b/LawCompany/LawCompanyBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,59 @@ +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; + +namespace LawCompanyBusinessLogic.MailWorker +{ + public abstract class AbstractMailWorker + { + protected string _mailLogin = string.Empty; + protected string _mailPassword = string.Empty; + protected string _smtpClientHost = string.Empty; + protected int _smtpClientPort; + protected string _popHost = string.Empty; + protected int _popPort; + private readonly IExecutorLogic _executorLogic; + private readonly ILogger _logger; + + public AbstractMailWorker(ILogger logger, IExecutorLogic executorLogic) + { + _logger = logger; + _executorLogic = executorLogic; + } + + public void MailConfig(MailConfigBindingModel config) + { + _mailLogin = config.MailLogin; + _mailPassword = config.MailPassword; + _smtpClientHost = config.SmtpClientHost; + _smtpClientPort = config.SmtpClientPort; + _popHost = config.PopHost; + _popPort = config.PopPort; + _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + } + + public async void MailSendAsync(MailSendInfoBindingModel info) + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + + if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0) + { + return; + } + + if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + { + return; + } + + _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject); + + await SendMailAsync(info); + } + + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + } +} diff --git a/LawCompany/LawCompanyBusinessLogic/MailWorker/MailKitWorker.cs b/LawCompany/LawCompanyBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..c69c49f --- /dev/null +++ b/LawCompany/LawCompanyBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,44 @@ +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using System.Net.Mail; +using System.Net.Mime; +using System.Net; +using System.Text; + +namespace LawCompanyBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IExecutorLogic _executorLogic) : base(logger, _executorLogic) { } + + protected override async Task SendMailAsync(MailSendInfoBindingModel info) + { + using var objMailMessage = new MailMessage(); + using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); + + try + { + objMailMessage.From = new MailAddress(_mailLogin); + objMailMessage.To.Add(new MailAddress(info.MailAddress)); + objMailMessage.Subject = info.Subject; + objMailMessage.Body = info.Text; + objMailMessage.SubjectEncoding = Encoding.UTF8; + objMailMessage.BodyEncoding = Encoding.UTF8; + Attachment attachment = new Attachment("C:\\Reports\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); + objMailMessage.Attachments.Add(attachment); + + objSmtpClient.UseDefaultCredentials = false; + objSmtpClient.EnableSsl = true; + objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword); + + await Task.Run(() => objSmtpClient.Send(objMailMessage)); + } + catch (Exception) + { + throw; + } + } + } +} diff --git a/LawCompany/LawCompanyGuarantorApp/Properties/launchSettings.json b/LawCompany/LawCompanyGuarantorApp/Properties/launchSettings.json index 3474387..03211a1 100644 --- a/LawCompany/LawCompanyGuarantorApp/Properties/launchSettings.json +++ b/LawCompany/LawCompanyGuarantorApp/Properties/launchSettings.json @@ -1,21 +1,13 @@ -{ - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:19906", - "sslPort": 44345 - } - }, +{ "profiles": { "LawCompanyGuarantorApp": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:7250;http://localhost:5131", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7250;http://localhost:5131" }, "IIS Express": { "commandName": "IISExpress", @@ -24,5 +16,13 @@ "ASPNETCORE_ENVIRONMENT": "Development" } } + }, + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:19906", + "sslPort": 44345 + } } -} +} \ No newline at end of file