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!"
}
+