From e80dc53d6ff48123c796f388f0f0c87298af2bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Sun, 5 May 2024 14:28:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B2=20=D0=BE=D1=80=D0=B4=D0=B5=D1=80=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BA=D1=83=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D1=83=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MailWorker/AbstractMailWorker.cs | 4 +- .../MailWorker/MailKitWorker.cs | 1 - SushiBarBusinessLogic/OrderLogic.cs | 49 +++++++++++++++++-- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs b/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs index 5afe08c..77a797b 100644 --- a/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs +++ b/SushiBarBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -28,8 +28,8 @@ namespace SushiBarBusinessLogic.MailWorker _smtpClientPort = config.SmtpClientPort; _popHost = config.PopHost; _popPort = config.PopPort; - _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", - _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + _logger.LogDebug($"Config: {_mailLogin}, {_mailPassword}, " + + $"{_smtpClientHost}, {_smtpClientPort}, {_popHost}, {_popPort}"); } public async void MailSendAsync(MailSendInfoBindingModel info) { diff --git a/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs b/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs index 99483d8..4d359e8 100644 --- a/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs +++ b/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs @@ -71,6 +71,5 @@ namespace SushiBarBusinessLogic.MailWorker }); return list; } - } } diff --git a/SushiBarBusinessLogic/OrderLogic.cs b/SushiBarBusinessLogic/OrderLogic.cs index 7eb9afc..cb5e22d 100644 --- a/SushiBarBusinessLogic/OrderLogic.cs +++ b/SushiBarBusinessLogic/OrderLogic.cs @@ -6,6 +6,7 @@ using SushiBarContracts.ViewModels; using Microsoft.Extensions.Logging; using SushiBarDataModels.Enums; using System.Xml.Linq; +using SushiBarBusinessLogic.MailWorker; namespace SushiBarBusinessLogic.BusinessLogic { @@ -13,12 +14,17 @@ namespace SushiBarBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IClientStorage clientStorage; + private readonly AbstractMailWorker abstractMailWorker; static readonly object blocking = new object(); - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, + IClientStorage clientStorage, AbstractMailWorker abstractMailWorker) { _logger = logger; _orderStorage = orderStorage; + this.clientStorage = clientStorage; + this.abstractMailWorker = abstractMailWorker; } public OrderViewModel? ReadElement(OrderSearchModel model) @@ -86,8 +92,7 @@ namespace SushiBarBusinessLogic.BusinessLogic { CheckModel(model, false); var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (order.ImplementerId.HasValue) - model.ImplementerId = order.ImplementerId; + if (order == null) { _logger.LogWarning("Change status operation failed. Order not found"); @@ -100,6 +105,9 @@ namespace SushiBarBusinessLogic.BusinessLogic return false; } + if (order.ImplementerId.HasValue) + model.ImplementerId = order.ImplementerId; + model.Status = orderStatus; if (model.Status == OrderStatus.Готов) @@ -115,9 +123,44 @@ namespace SushiBarBusinessLogic.BusinessLogic _logger.LogWarning("Change status operation failed"); return false; } + + var clientView = clientStorage.GetElement(new ClientSearchModel { Id = order.ClientId }); + if (clientView != null) + SendMail(clientView, order); return true; } + private void SendMail(ClientViewModel clientView, OrderViewModel orderView) + { + if(clientView == null || orderView == null) + { + return; + } + MailSendInfoBindingModel mailSendInfoBindingModel; + + if(orderView.Status == OrderStatus.Принят) + { + mailSendInfoBindingModel = new MailSendInfoBindingModel + { + MailAddress = clientView.Email, + Subject = $"Заказ под номером {orderView.Id}", + Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " + + $"был принят" + }; + } + else + { + mailSendInfoBindingModel = new MailSendInfoBindingModel + { + MailAddress = clientView.Email, + Subject = $"Заказ под номером {orderView.Id}", + Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " + + $"поменял статус на {orderView.Status}" + }; + } + abstractMailWorker.MailSendAsync(mailSendInfoBindingModel); + } + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null)