diff --git a/Bank/BankBusinessLogic/BankBusinessLogic.csproj b/Bank/BankBusinessLogic/BankBusinessLogic.csproj index 4ccace6..85eb7e4 100644 --- a/Bank/BankBusinessLogic/BankBusinessLogic.csproj +++ b/Bank/BankBusinessLogic/BankBusinessLogic.csproj @@ -8,6 +8,7 @@ + diff --git a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs index 493d72c..e0c5fd1 100644 --- a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs @@ -8,8 +8,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using ConfectioneryBusinessLogic.OfficePackage; -using ConfectioneryBusinessLogic.OfficePackage.HelperModels; +using BankBusinessLogic.OfficePackage; +using BankBusinessLogic.OfficePackage.HelperModels; namespace BankBusinessLogic.BusinessLogics { diff --git a/Bank/BankBusinessLogic/MailWorker/AbstractMailWorker.cs b/Bank/BankBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..c7677f3 --- /dev/null +++ b/Bank/BankBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,66 @@ +using BankContracts.BindingModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankBusinessLogic.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 ILogger _logger; + + public AbstractMailWorker(ILogger logger) + { + _logger = logger; + } + + 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/Bank/BankBusinessLogic/MailWorker/MailKitWorker.cs b/Bank/BankBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..4255a2f --- /dev/null +++ b/Bank/BankBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,47 @@ +using BankContracts.BindingModels; +using BankContracts.BusinessLogicsContracts; +using MailKit.Net.Pop3; +using MailKit.Security; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace BankBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger) : base(logger) { } + + 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; + objMailMessage.Attachments.Add(new Attachment(info.Attachment, info.FileName, "application/pdf")); + + 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/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 6576e14..b161605 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -1,12 +1,12 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; -using ConfectioneryBusinessLogic.OfficePackage.HelperModels; +using BankBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage +namespace BankBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcel { diff --git a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 2039bb3..e76e7b2 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -1,12 +1,12 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; -using ConfectioneryBusinessLogic.OfficePackage.HelperModels; +using BankBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage +namespace BankBusinessLogic.OfficePackage { public abstract class AbstractSaveToPdf { diff --git a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 898f037..29777bf 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -1,12 +1,12 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; -using ConfectioneryBusinessLogic.OfficePackage.HelperModels; +using BankBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage +namespace BankBusinessLogic.OfficePackage { public abstract class AbstractSaveToWord { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/Bank/BankBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs index b379cbc..2d7b0d6 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperEnums +namespace BankBusinessLogic.OfficePackage.HelperEnums { public enum ExcelStyleInfoType { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/Bank/BankBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs index 4b613dc..07b8275 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperEnums +namespace BankBusinessLogic.OfficePackage.HelperEnums { public enum PdfParagraphAlignmentType { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/Bank/BankBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs index 7efdd1f..95bdb77 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperEnums +namespace BankBusinessLogic.OfficePackage.HelperEnums { public enum WordJustificationType { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs index 09f3ec5..d83d2a7 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -1,11 +1,11 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperEnums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class ExcelCellParameters { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index 0ca541d..eda260d 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class ExcelInfo { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs index 81e9476..2d6ab4b 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class ExcelMergeParameters { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index e9ce719..9c9be5b 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class PdfInfo { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs index 87f32c0..594d78e 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -1,11 +1,11 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperEnums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class PdfParagraph { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs index 5847af8..44054a6 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -1,11 +1,11 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperEnums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class PdfRowParameters { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index a19474c..166fc5e 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class WordInfo { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs index 206e712..4d7590f 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class WordParagraph { diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs index 838e43b..4a806ad 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -1,11 +1,11 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperEnums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels +namespace BankBusinessLogic.OfficePackage.HelperModels { public class WordTextProperties { diff --git a/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 28ee885..e9413bd 100644 --- a/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -1,5 +1,5 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; -using ConfectioneryBusinessLogic.OfficePackage.HelperModels; +using BankBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml.Office2010.Excel; using DocumentFormat.OpenXml.Office2013.Excel; using DocumentFormat.OpenXml.Packaging; @@ -11,7 +11,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.Implements +namespace BankBusinessLogic.OfficePackage.Implements { public class SaveToExcel : AbstractSaveToExcel { diff --git a/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index ebef09f..e049570 100644 --- a/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -1,5 +1,5 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; -using ConfectioneryBusinessLogic.OfficePackage.HelperModels; +using BankBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperModels; using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.Rendering; @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.Implements +namespace BankBusinessLogic.OfficePackage.Implements { public class SaveToPdf : AbstractSaveToPdf { diff --git a/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 37fbb0a..ce62e85 100644 --- a/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -1,5 +1,5 @@ -using ConfectioneryBusinessLogic.OfficePackage.HelperEnums; -using ConfectioneryBusinessLogic.OfficePackage.HelperModels; +using BankBusinessLogic.OfficePackage.HelperEnums; +using BankBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using DocumentFormat.OpenXml; @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryBusinessLogic.OfficePackage.Implements +namespace BankBusinessLogic.OfficePackage.Implements { public class SaveToWord : AbstractSaveToWord { diff --git a/Bank/BankContracts/BindingModels/MailConfigBindingModel.cs b/Bank/BankContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..002205d --- /dev/null +++ b/Bank/BankContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + + public string MailPassword { get; set; } = string.Empty; + + public string SmtpClientHost { get; set; } = string.Empty; + + public int SmtpClientPort { get; set; } + + public string PopHost { get; set; } = string.Empty; + + public int PopPort { get; set; } + } +} diff --git a/Bank/BankContracts/BindingModels/MailSendInfoBindingModel.cs b/Bank/BankContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..44e2108 --- /dev/null +++ b/Bank/BankContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + public string Subject { get; set; } = string.Empty; + public string Text { get; set; } = string.Empty; + public MemoryStream Attachment { get; set; } = new MemoryStream(); + public string FileName { get; set; } = string.Empty; + + } +} diff --git a/Bank/OperatorApp/Controllers/HomeController.cs b/Bank/OperatorApp/Controllers/HomeController.cs index 4657410..6a86cbc 100644 --- a/Bank/OperatorApp/Controllers/HomeController.cs +++ b/Bank/OperatorApp/Controllers/HomeController.cs @@ -1,9 +1,11 @@ -using BankContracts.BindingModels; +using BankBusinessLogic.MailWorker; +using BankContracts.BindingModels; using BankContracts.BusinessLogicsContracts; using BankContracts.SearchModels; using BankContracts.ViewModels; using BankDatabaseImplement.Models; using BankDataModels.Models; +using MailKit; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore.Metadata; using OperatorApp.Models; @@ -19,8 +21,9 @@ namespace OperatorApp.Controllers private readonly ITransferLogic _transferLogic; private readonly IOperatorLogic _operatorLogic; private readonly IReportLogic _reportLogic; + private readonly AbstractMailWorker _mailWorker; - public HomeController(ILogger logger, IDealLogic dealLogic, IPaymentLogic paymentLogic, ITransferLogic transferLogic, IOperatorLogic operatorLogic, IReportLogic reportLogic) + public HomeController(ILogger logger, IDealLogic dealLogic, IPaymentLogic paymentLogic, ITransferLogic transferLogic, IOperatorLogic operatorLogic, IReportLogic reportLogic, AbstractMailWorker mailWorker) { _logger = logger; _dealLogic = dealLogic; @@ -28,6 +31,7 @@ namespace OperatorApp.Controllers _transferLogic = transferLogic; _operatorLogic = operatorLogic; _reportLogic = reportLogic; + _mailWorker = mailWorker; } public IActionResult Index() @@ -229,7 +233,8 @@ namespace OperatorApp.Controllers { if (APIClient.Operator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($""); + Response.Redirect("/Home/Enter"); } ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id }); return View(); @@ -269,10 +274,26 @@ namespace OperatorApp.Controllers return View(new ReportBindingModel()); } [HttpPost] - public IActionResult TransfersReport(DateTime dateFrom, DateTime dateTo) + public void TransfersReport(DateTime dateFrom, DateTime dateTo) { MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo }); - return File(report, "application/pdf", "test.pdf"); + try + { + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + Subject = "Отчёт о закупках", + Text = "От банка \"Вы банкрот\"", + MailAddress = "", + FileName = "test.pdf", + Attachment = report + }); + Response.Redirect("/"); + } + catch (Exception ex) + { + Response.WriteAsync($""); + Response.Redirect("/"); + } } } } \ No newline at end of file diff --git a/Bank/OperatorApp/Program.cs b/Bank/OperatorApp/Program.cs index 46d0cad..641b38a 100644 --- a/Bank/OperatorApp/Program.cs +++ b/Bank/OperatorApp/Program.cs @@ -2,9 +2,11 @@ using BankBusinessLogic.BusinessLogics; using BankContracts.BusinessLogicsContracts; using BankContracts.StoragesContracts; using BankDatabaseImplement.Implements; -using ConfectioneryBusinessLogic.OfficePackage; -using ConfectioneryBusinessLogic.OfficePackage.Implements; +using BankBusinessLogic.OfficePackage; +using BankBusinessLogic.OfficePackage.Implements; using OperatorApp; +using BankBusinessLogic.MailWorker; +using BankContracts.BindingModels; var builder = WebApplication.CreateBuilder(args); @@ -22,6 +24,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddSingleton(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -31,6 +34,25 @@ builder.Services.AddTransient(); var app = builder.Build(); +try +{ + var mailSender = app.Services.GetService(); + mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = builder.Configuration["MailLogin"] ?? string.Empty, + MailPassword = builder.Configuration["MailPassword"] ?? string.Empty, + SmtpClientHost = builder.Configuration["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration["SmtpClientPort"]), + PopHost = builder.Configuration["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration["PopPort"]) + }); +} +catch (Exception ex) +{ + var logger = app.Services.GetService(); + logger?.LogError(ex, " "); +} + APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. diff --git a/Bank/OperatorApp/Views/Home/CreateTransfer.cshtml b/Bank/OperatorApp/Views/Home/CreateTransfer.cshtml index 9e20259..68200a0 100644 --- a/Bank/OperatorApp/Views/Home/CreateTransfer.cshtml +++ b/Bank/OperatorApp/Views/Home/CreateTransfer.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["Title"] = "CreatePayment"; + ViewData["Title"] = "CreateTransfer"; }

Создание зачисления

diff --git a/Bank/OperatorApp/appsettings.json b/Bank/OperatorApp/appsettings.json index 06180ac..a96ea2a 100644 --- a/Bank/OperatorApp/appsettings.json +++ b/Bank/OperatorApp/appsettings.json @@ -6,5 +6,11 @@ } }, "AllowedHosts": "*", - "IPAddress": "http://localhost:5225" + "IPAddress": "http://localhost:5225", + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "rpplab7@gmail.com", + "MailPassword": "edjc dmsf pqne gxwy" }