From 005c8c0b3e786095ab4a7e007390503ad6f2fc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Fri, 21 Apr 2023 16:16:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B2=D1=81?= =?UTF-8?q?=D1=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FoodOrders/FoodOrders/Program.cs | 5 +++-- .../BusinessLogics/OrderLogic.cs | 16 ++++++++++------ .../MailWorker/AbstractMailWorker.cs | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/FoodOrders/FoodOrders/Program.cs b/FoodOrders/FoodOrders/Program.cs index 1bd2605..6dcef03 100644 --- a/FoodOrders/FoodOrders/Program.cs +++ b/FoodOrders/FoodOrders/Program.cs @@ -30,8 +30,7 @@ namespace FoodOrdersView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - - Application.Run(_serviceProvider.GetRequiredService()); + try { var mailSender = _serviceProvider.GetService(); @@ -53,6 +52,8 @@ namespace FoodOrdersView var logger = _serviceProvider.GetService(); logger?.LogError(ex, " "); } + + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) diff --git a/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs index a23a9b2..8c93963 100644 --- a/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FoodOrders/FoodOrdersBusinessLogic/BusinessLogics/OrderLogic.cs @@ -63,13 +63,14 @@ namespace FoodOrdersBusinessLogic.BusinessLogics return false; } model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) + var order = _orderStorage.Insert(model); + if (order == null) { model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } - SendToClient(model.ClientId, $"Заказ №{model.Id}", $"Заказ №{model.Id} от {model.DateCreate} на сумму {model.Sum} был создан."); + SendToClient(order.ClientId, $"Заказ №{order.Id}", $"Заказ №{order.Id} от {order.DateCreate} на сумму {order.Sum} принят."); return true; } @@ -143,21 +144,23 @@ namespace FoodOrdersBusinessLogic.BusinessLogics model.DateImplement = viewModel.DateImplement; } CheckModel(model, false); - if (_orderStorage.Update(model) == null) + var order = _orderStorage.Update(model); + if (order == null) { _logger.LogWarning("Change status operation failed"); return false; } - SendToClient(model.ClientId, $"Заказ №{model.Id}", $"У заказа №{model.Id} изменен статус на {model.Status}."); + + SendToClient(order.ClientId, $"Заказ №{order.Id}", $"У заказа №{order.Id} изменен статус на {order.Status}."); return true; } - private void SendToClient(int clientId, string subject, string text) + private bool SendToClient(int clientId, string subject, string text) { var client = _clientLogic.ReadElement(new() { Id = clientId }); if (client == null) { - return; + return false; } _mailWorker.MailSendAsync(new() { @@ -165,6 +168,7 @@ namespace FoodOrdersBusinessLogic.BusinessLogics Subject = subject, Text = text }); + return true; } } } diff --git a/FoodOrders/FoodOrdersBusinessLogic/MailWorker/AbstractMailWorker.cs b/FoodOrders/FoodOrdersBusinessLogic/MailWorker/AbstractMailWorker.cs index b860472..27eabe9 100644 --- a/FoodOrders/FoodOrdersBusinessLogic/MailWorker/AbstractMailWorker.cs +++ b/FoodOrders/FoodOrdersBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -2,6 +2,7 @@ using FoodOrdersContracts.BindingModels; using FoodOrdersContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; +using System.Net.Mail; namespace FoodOrdersBusinessLogic.MailWorker {