исправлен неисправленный конфликт с базовой части

This commit is contained in:
Данияр Аглиуллов 2023-03-17 20:32:41 +04:00
parent 72a1f2e75d
commit fd6e638e70

View File

@ -1,4 +1,5 @@
using ConfectioneryContracts.BindingModels; using ConfectioneryBusinessLogic.MailWorker;
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts; using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.SearchModels; using ConfectioneryContracts.SearchModels;
using ConfectioneryContracts.StoragesContract; using ConfectioneryContracts.StoragesContract;
@ -14,13 +15,17 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IPastryStorage _pastryStorage; private readonly IPastryStorage _pastryStorage;
private readonly IShopLogic _shopLogic; private readonly IShopLogic _shopLogic;
private readonly AbstractMailWorker _mailWorker;
private readonly IClientLogic _clientLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IPastryStorage pastryStorage, IShopLogic shopLogic) public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IPastryStorage pastryStorage, IShopLogic shopLogic, IClientLogic clientLogic, AbstractMailWorker mailWorker)
{ {
_logger = logger; _logger = logger;
_shopLogic = shopLogic; _shopLogic = shopLogic;
_pastryStorage = pastryStorage; _pastryStorage = pastryStorage;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_mailWorker = mailWorker;
_clientLogic = clientLogic;
} }
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
@ -33,11 +38,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
} }
model.Status = OrderStatus.Принят; model.Status = OrderStatus.Принят;
model.DateCreate = DateTime.Now; model.DateCreate = DateTime.Now;
if (_orderStorage.Insert(model) == null) var result = _orderStorage.Insert(model);
if (result == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
SendOrderStatusMail(result.ClientId, $"Новый заказ создан. Номер заказа #{result.Id}", $"Заказ #{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят");
return true; return true;
} }
@ -122,11 +129,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
model.PastryId = vmodel.PastryId; model.PastryId = vmodel.PastryId;
model.Sum = vmodel.Sum; model.Sum = vmodel.Sum;
model.Count= vmodel.Count; model.Count= vmodel.Count;
if (_orderStorage.Update(model) == null) var result = _orderStorage.Update(model);
if (result == null)
{ {
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
} }
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}");
return true; return true;
} }
@ -146,5 +155,21 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id); _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element; return element;
} }
private bool SendOrderStatusMail(int clientId, string subject, string text)
{
var client = _clientLogic.ReadElement(new() { Id = clientId });
if (client == null)
{
return false;
}
_mailWorker.MailSendAsync(new()
{
MailAddress = client.Email,
Subject = subject,
Text = text
});
return true;
}
} }
} }