OrderLogic edited: added sending msgs
This commit is contained in:
parent
53b8b71f89
commit
e61380ff6b
@ -1,4 +1,5 @@
|
|||||||
using JewelryStoreContracts.BindingModels;
|
using JewelryStoreBusinessLogic.MailWorker;
|
||||||
|
using JewelryStoreContracts.BindingModels;
|
||||||
using JewelryStoreContracts.BusinessLogicsContracts;
|
using JewelryStoreContracts.BusinessLogicsContracts;
|
||||||
using JewelryStoreContracts.SearchModels;
|
using JewelryStoreContracts.SearchModels;
|
||||||
using JewelryStoreContracts.StoragesContracts;
|
using JewelryStoreContracts.StoragesContracts;
|
||||||
@ -17,12 +18,16 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
|
private readonly IClientLogic _clientLogic;
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
}
|
_mailWorker = mailWorker;
|
||||||
|
_clientLogic = clientLogic;
|
||||||
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -35,15 +40,16 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
|
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
|
var result = _orderStorage.Update(model);
|
||||||
|
|
||||||
if (_orderStorage.Insert(model) == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
model.Status = OrderStatus.Неизвестен;
|
model.Status = OrderStatus.Неизвестен;
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SendOrderMessage(result.ClientId, $"Установка ПО, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||||
@ -75,18 +81,38 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
|
|||||||
model.JewelId = vmodel.JewelId;
|
model.JewelId = vmodel.JewelId;
|
||||||
model.Sum = vmodel.Sum;
|
model.Sum = vmodel.Sum;
|
||||||
model.Count = vmodel.Count;
|
model.Count = vmodel.Count;
|
||||||
|
var result = _orderStorage.Update(model);
|
||||||
|
|
||||||
if (_orderStorage.Update(model) == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SendOrderMessage(result.ClientId, $"Установка ПО, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
private bool SendOrderMessage(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user