From 76816dd5d39d972e15411f8a0318e203a2d21ebd Mon Sep 17 00:00:00 2001 From: Alina Batylkina Date: Wed, 21 Jun 2023 19:25:26 +0400 Subject: [PATCH] fix --- .../BusinessLogics/ReportLogic.cs | 10 +++---- .../BusinessLogics/VisitorLogic.cs | 23 +++++++++++----- .../BusinessLogicsContracts/IVisitorLogic.cs | 1 + .../CanteenDatabase.cs | 2 +- .../Controllers/ManagerController.cs | 2 +- .../Controllers/VisitorController.cs | 26 ++++++++++++++++++- .../Controllers/HomeController.cs | 3 +-- 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs index 7e9d0d3..e9e4ee9 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/ReportLogic.cs @@ -141,13 +141,13 @@ namespace CanteenBusinessLogic.BusinessLogics Lunch = lunch, Cooks = new List() }; - var lunchProducts = lunch.LunchProducts.Keys.ToList(); - foreach (var productId in lunchProducts) + var lunchOrders = lunch.LunchOrders.Keys.ToList(); + foreach (var orderId in lunchOrders) { - var product = productStorage.GetElement(new ProductSearchModel { Id = productId }); - var productCooks = product.ProductCooks.Keys.ToList(); + var order = orderStorage.GetElement(new OrderSearchModel { Id = orderId }); + var orderCooks = order.OrderCooks.Keys.ToList(); - foreach (var cookId in productCooks) + foreach (var cookId in orderCooks) { if (record.Cooks.Where(cook => cook.Id == cookId).ToList().Count == 0) { diff --git a/Canteen/CanteenBusinessLogic/BusinessLogics/VisitorLogic.cs b/Canteen/CanteenBusinessLogic/BusinessLogics/VisitorLogic.cs index 0ef5dac..765bcc6 100644 --- a/Canteen/CanteenBusinessLogic/BusinessLogics/VisitorLogic.cs +++ b/Canteen/CanteenBusinessLogic/BusinessLogics/VisitorLogic.cs @@ -1,14 +1,10 @@ -using CanteenContracts.BindingModels; +using CanteenBusinessLogic.MailWorker; +using CanteenContracts.BindingModels; using CanteenContracts.BusinessLogicsContracts; using CanteenContracts.SearchModel; using CanteenContracts.StoragesContracts; using CanteenContracts.View; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CanteenBusinessLogic.BusinessLogics { @@ -16,11 +12,13 @@ namespace CanteenBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IVisitorStorage _visitorStorage; + private readonly AbstractMailWorker _mailWorker; - public VisitorLogic(ILogger logger, IVisitorStorage visitorStorage) + public VisitorLogic(ILogger logger, IVisitorStorage visitorStorage, AbstractMailWorker mailWorker) { _logger = logger; _visitorStorage = visitorStorage; + _mailWorker = mailWorker; } public bool Create(VisitorBindingModel model) @@ -97,6 +95,17 @@ namespace CanteenBusinessLogic.BusinessLogics return true; } + public bool SendMail(MailSendInfoBindingModel emailInfo) + { + _mailWorker.MailSendAsync(new() + { + MailAddress = emailInfo.MailAddress, + Subject = emailInfo.Subject, + Path = emailInfo.Path, + }); + + return true; + } private void CheckModel(VisitorBindingModel model, bool withParams = true) { if (model == null) diff --git a/Canteen/CanteenContracts/BusinessLogicsContracts/IVisitorLogic.cs b/Canteen/CanteenContracts/BusinessLogicsContracts/IVisitorLogic.cs index 939bb90..7f7a2c2 100644 --- a/Canteen/CanteenContracts/BusinessLogicsContracts/IVisitorLogic.cs +++ b/Canteen/CanteenContracts/BusinessLogicsContracts/IVisitorLogic.cs @@ -15,5 +15,6 @@ namespace CanteenContracts.BusinessLogicsContracts VisitorViewModel? ReadElement(VisitorSearchModel model); bool Create(VisitorBindingModel model); bool Update(VisitorBindingModel model); + bool SendMail(MailSendInfoBindingModel emailInfo); } } diff --git a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs index 7ef45cc..a924378 100644 --- a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs +++ b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs @@ -11,7 +11,7 @@ namespace CanteenDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=MOVAVI-DESKTOP\SQLEXPRESS;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-A68O3K0;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/Canteen/CanteenRestApi/Controllers/ManagerController.cs b/Canteen/CanteenRestApi/Controllers/ManagerController.cs index e38866d..1cadbf2 100644 --- a/Canteen/CanteenRestApi/Controllers/ManagerController.cs +++ b/Canteen/CanteenRestApi/Controllers/ManagerController.cs @@ -72,7 +72,7 @@ namespace CanteenRestApi.Controllers { try { - string path = $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}111111.pdf"; + string path = $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}.pdf"; _report.saveCooksToPdfFile(new ReportBindingModel { FileName = path, diff --git a/Canteen/CanteenRestApi/Controllers/VisitorController.cs b/Canteen/CanteenRestApi/Controllers/VisitorController.cs index 5347326..44bd80e 100644 --- a/Canteen/CanteenRestApi/Controllers/VisitorController.cs +++ b/Canteen/CanteenRestApi/Controllers/VisitorController.cs @@ -12,11 +12,13 @@ namespace CanteenRestApi.Controllers { private readonly ILogger _logger; private readonly IVisitorLogic _logic; + private readonly IReportLogic _report; - public VisitorController(IVisitorLogic logic, ILogger logger) + public VisitorController(IVisitorLogic logic, IReportLogic report, ILogger logger) { _logger = logger; _logic = logic; + _report = report; } [HttpGet] @@ -64,5 +66,27 @@ namespace CanteenRestApi.Controllers throw; } } + [HttpPost] + public void SendEmail(MailSendInfoBindingModel emailInfo) + { + try + { + string path = $"C:\\PdfReports\\{DateTime.Now.ToString("HH.mm.ss_dd.MM.yyyy")}.pdf"; + _report.saveLunchesToPdfFile(new ReportBindingModel + { + FileName = path, + UserId = emailInfo.report.UserId, + DateBefore = emailInfo.report.DateBefore, + DateAfter = emailInfo.report.DateAfter + }); + emailInfo.Path = path; + _logic.SendMail(emailInfo); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error during updating"); + throw; + } + } } } diff --git a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs index 9c07c26..9ec48a9 100644 --- a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs +++ b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs @@ -574,8 +574,7 @@ namespace CanteenVisitorApp.Controllers Subject = "Отчет", report = model }); - APIClient.PostRequest("api/main/SaveCooksToEMAIL", model); - Response.Redirect("Index"); + Response.Redirect("Report"); } } } \ No newline at end of file