From 54a95ee87fe0d8fffb5276ef4072ec6132c2238e 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: Mon, 6 May 2024 00:26:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=95=D0=A0=D0=A2=D0=9E=D0=92=20=D0=9F?= =?UTF-8?q?=D0=A0=D0=9E=D0=91=D0=95=D0=9B=20=D0=90=D0=90=D0=90=D0=90=D0=90?= =?UTF-8?q?=D0=90=D0=90=D0=90=D0=90=D0=90=D0=A0=D0=A0=D0=A0=D0=A0=D0=A0?= =?UTF-8?q?=D0=A0=D0=A0=D0=A0=D0=A0=D0=A0=D0=A0=20=D0=98=20=D0=93=D0=9C?= =?UTF-8?q?=D0=95=D0=99=D0=9B=D0=9E=D0=92=D0=A1=D0=9A=D0=90=D0=AF=20=D0=9F?= =?UTF-8?q?=D0=9E=D0=A7=D0=A2=D0=90!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/App.config | 11 +++---- SushiBar/Program.cs | 6 ++-- SushiBarBusinessLogic/MessageInfoLogic.cs | 1 + SushiBarBusinessLogic/OrderLogic.cs | 29 ++++++++++--------- SushiBarClientApp/Views/Home/Mails.cshtml | 2 +- .../Implements/MessageInfoStorage.cs | 13 ++++++++- SushiBarRestApi/appsettings.json | 13 +++++---- 7 files changed, 47 insertions(+), 28 deletions(-) diff --git a/SushiBar/App.config b/SushiBar/App.config index 9071b7d..92d5f0a 100644 --- a/SushiBar/App.config +++ b/SushiBar/App.config @@ -1,11 +1,12 @@  - - - + + + - - + + + diff --git a/SushiBar/Program.cs b/SushiBar/Program.cs index 5a1c3dd..35cf6d1 100644 --- a/SushiBar/Program.cs +++ b/SushiBar/Program.cs @@ -43,12 +43,12 @@ namespace SushiBar MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, - SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClient Port"]), + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) }); // - var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 5000); } catch (Exception ex) { @@ -80,8 +80,8 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/SushiBarBusinessLogic/MessageInfoLogic.cs b/SushiBarBusinessLogic/MessageInfoLogic.cs index 8085938..856d6a0 100644 --- a/SushiBarBusinessLogic/MessageInfoLogic.cs +++ b/SushiBarBusinessLogic/MessageInfoLogic.cs @@ -23,6 +23,7 @@ namespace SushiBarBusinessLogic if(messageStorage.Insert(model) == null) { logger.LogWarning("Insert message operation failed"); + return false; } return true; } diff --git a/SushiBarBusinessLogic/OrderLogic.cs b/SushiBarBusinessLogic/OrderLogic.cs index 5c34234..3a717a0 100644 --- a/SushiBarBusinessLogic/OrderLogic.cs +++ b/SushiBarBusinessLogic/OrderLogic.cs @@ -18,7 +18,7 @@ namespace SushiBarBusinessLogic.BusinessLogic 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; @@ -60,18 +60,21 @@ namespace SushiBarBusinessLogic.BusinessLogic public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) return false; + if (model.Status != OrderStatus.Неизвестен) + { + return false; + } model.Status = OrderStatus.Принят; - var order = _orderStorage.Insert(model); - if (order == null) { _logger.LogWarning("Insert operation failed"); return false; } - var client = clientStorage.GetElement(new() { Id = order!.ClientId }); - SendMail(client, order); + var clientView = clientStorage.GetElement(new() { Id = order.ClientId }); + + if (clientView != null) + SendMail(clientView, order); return true; } @@ -97,7 +100,7 @@ namespace SushiBarBusinessLogic.BusinessLogic { CheckModel(model, false); var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - + if (order == null) { _logger.LogWarning("Change status operation failed. Order not found"); @@ -137,18 +140,18 @@ namespace SushiBarBusinessLogic.BusinessLogic public void SendMail(ClientViewModel clientView, OrderViewModel orderView) { - if(clientView == null && orderView == null) + if (clientView == null && orderView == null) { return; } MailSendInfoBindingModel mailSendInfoBindingModel; - if(orderView.Status == OrderStatus.Принят) + if (orderView.Status == OrderStatus.Принят) { mailSendInfoBindingModel = new MailSendInfoBindingModel { - MailAddress = clientView.Email, + MailAddress = clientView!.Email, Subject = $"Заказ под номером {orderView.Id}", Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " + $"был принят" @@ -158,7 +161,7 @@ namespace SushiBarBusinessLogic.BusinessLogic { mailSendInfoBindingModel = new MailSendInfoBindingModel { - MailAddress = clientView.Email, + MailAddress = clientView!.Email, Subject = $"Заказ под номером {orderView.Id}", Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " + $"поменял статус на {orderView.Status}" @@ -186,8 +189,8 @@ namespace SushiBarBusinessLogic.BusinessLogic if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) throw new ArithmeticException("Заказ должен быть выдан позже, чем был создан"); - _logger.LogInformation("Sushi. SushiId:{SushiId}. Count:{ Count}. Sum:{ Sum}. Id: { Id}", - model.SushiId, model.Count, model.Sum, model.Id); + _logger.LogInformation("Sushi. SushiId:{SushiId}. Count:{ Count}. Sum:{ Sum}. Id: { Id}", + model.SushiId, model.Count, model.Sum, model.Id); } } } diff --git a/SushiBarClientApp/Views/Home/Mails.cshtml b/SushiBarClientApp/Views/Home/Mails.cshtml index 26eea6f..394cf54 100644 --- a/SushiBarClientApp/Views/Home/Mails.cshtml +++ b/SushiBarClientApp/Views/Home/Mails.cshtml @@ -4,7 +4,7 @@ ViewData["Title"] = "Mails"; }
-

Заказы

+

Письма

@{ diff --git a/SushiBarDatabaseImplement/Implements/MessageInfoStorage.cs b/SushiBarDatabaseImplement/Implements/MessageInfoStorage.cs index 37f3368..a01ecb1 100644 --- a/SushiBarDatabaseImplement/Implements/MessageInfoStorage.cs +++ b/SushiBarDatabaseImplement/Implements/MessageInfoStorage.cs @@ -51,10 +51,21 @@ namespace SushiBarDatabaseImplement.Implements { using var context = new SushiBarDatabase(); var newMessage = MessageInfo.Create(model); - if(newMessage == null) return null; + if (newMessage == null) return null; context.Messages.Add(newMessage); context.SaveChanges(); return newMessage.GetViewModel; + + /* using var context = new SushiBarDatabase(); + model.ClientId = context.Clients.FirstOrDefault(x => x.Email.Equals(model.SenderName))?.Id; + var message = MessageInfo.Create(model); + if (message == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId))) + { + return null; + } + context.Messages.Add(message); + context.SaveChanges(); + return message.GetViewModel;*/ } } } diff --git a/SushiBarRestApi/appsettings.json b/SushiBarRestApi/appsettings.json index 53d95f6..0f7d457 100644 --- a/SushiBarRestApi/appsettings.json +++ b/SushiBarRestApi/appsettings.json @@ -5,11 +5,14 @@ "Microsoft.AspNetCore": "Warning" } }, + "AllowedHosts": "*", - "SmtpClientHost": "smtp.mail.com", - "SmtpClientPort": "587", - "PopHost": "pop.gmail.com", + + "SmtpClientHost": "smtp.beget.com", + "SmtpClientPort": "2525", + "PopHost": "pop.beget.com", "PopPort": "995", - "MailLogin": "qwertyelenatimakova@gmail.com", - "MailPassword": "616Lena!" + "MailLogin": "sushishop@ekallin.ru", + "MailPassword": "8j#HWiCBiI*I!" } +