отступы
This commit is contained in:
parent
d10438b7a7
commit
c853623a81
@ -9,44 +9,44 @@ using FishFactoryDataModels.Enums;
|
|||||||
|
|
||||||
namespace FishFactoryBusinessLogic.BusinessLogics
|
namespace FishFactoryBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class OrderLogic : IOrderLogic
|
public class OrderLogic : IOrderLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
private readonly AbstractMailWorker _mailWorker;
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
private readonly IClientLogic _clientLogic;
|
private readonly IClientLogic _clientLogic;
|
||||||
static readonly object _locker = new object();
|
static readonly object _locker = new object();
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
_mailWorker = mailWorker;
|
_mailWorker = mailWorker;
|
||||||
_clientLogic = clientLogic;
|
_clientLogic = clientLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (model.Status != OrderStatus.Неизвестен)
|
if (model.Status != OrderStatus.Неизвестен)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
var result = _orderStorage.Insert(model);
|
var result = _orderStorage.Insert(model);
|
||||||
if (result == 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} принят");
|
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)
|
||||||
{
|
{
|
||||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||||
if (viewModel == null)
|
if (viewModel == null)
|
||||||
{
|
{
|
||||||
@ -54,10 +54,10 @@ namespace FishFactoryBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
if (viewModel.Status + 1 != newStatus)
|
if (viewModel.Status + 1 != newStatus)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
|
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -67,45 +67,45 @@ namespace FishFactoryBusinessLogic.BusinessLogics
|
|||||||
var result = _orderStorage.Update(model);
|
var result = _orderStorage.Update(model);
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
model.Status--;
|
model.Status--;
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SendOrderMessage(result.ClientId, $"Рыбный завод, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}");
|
SendOrderMessage(result.ClientId, $"Рыбный завод, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
lock (_locker)
|
lock (_locker)
|
||||||
{
|
{
|
||||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
}
|
||||||
{
|
|
||||||
return StatusUpdate(model, OrderStatus.Выдан);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool FinishOrder(OrderBindingModel model)
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return StatusUpdate(model, OrderStatus.Готов);
|
return StatusUpdate(model, OrderStatus.Выдан);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Order. OrderID:{Id}", model?.Id);
|
return StatusUpdate(model, OrderStatus.Готов);
|
||||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
}
|
||||||
if (list == null)
|
|
||||||
{
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
_logger.LogWarning("ReadList return null list");
|
{
|
||||||
return null;
|
_logger.LogInformation("Order. OrderID:{Id}", model?.Id);
|
||||||
}
|
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
if (list == null)
|
||||||
return list;
|
{
|
||||||
}
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
@ -125,29 +125,29 @@ namespace FishFactoryBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
if (!withParams)
|
if (!withParams)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (model.CannedId < 0)
|
if (model.CannedId < 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Некорректный идентификатор у консервы", nameof(model.CannedId));
|
throw new ArgumentNullException("Некорректный идентификатор у консервы", nameof(model.CannedId));
|
||||||
}
|
}
|
||||||
if (model.Count <= 0)
|
if (model.Count <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Количество консервы в заказе должно быть больше 0", nameof(model.Count));
|
throw new ArgumentNullException("Количество консервы в заказе должно быть больше 0", nameof(model.Count));
|
||||||
}
|
}
|
||||||
if (model.Sum <= 0)
|
if (model.Sum <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. CannedId: { CannedId}", model.Id, model.Sum, model.CannedId);
|
_logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. CannedId: { CannedId}", model.Id, model.Sum, model.CannedId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SendOrderMessage(int clientId, string subject, string text)
|
private bool SendOrderMessage(int clientId, string subject, string text)
|
||||||
{
|
{
|
||||||
|
@ -7,68 +7,68 @@ using System.Net;
|
|||||||
|
|
||||||
namespace FishFactoryRestApi.Controllers
|
namespace FishFactoryRestApi.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/[controller]/[action]")]
|
[Route("api/[controller]/[action]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class ClientController : Controller
|
public class ClientController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly IClientLogic _logic;
|
private readonly IClientLogic _logic;
|
||||||
|
|
||||||
private readonly IMessageInfoLogic _mailLogic;
|
private readonly IMessageInfoLogic _mailLogic;
|
||||||
|
|
||||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
_mailLogic = mailLogic;
|
_mailLogic = mailLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ClientViewModel? Login(string login, string password)
|
public ClientViewModel? Login(string login, string password)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _logic.ReadElement(new ClientSearchModel
|
return _logic.ReadElement(new ClientSearchModel
|
||||||
{
|
{
|
||||||
Email = login,
|
Email = login,
|
||||||
Password = password
|
Password = password
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка входа в систему");
|
_logger.LogError(ex, "Ошибка входа в систему");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Register(ClientBindingModel model)
|
public void Register(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logic.Create(model);
|
_logic.Create(model);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка регистрации");
|
_logger.LogError(ex, "Ошибка регистрации");
|
||||||
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
|
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void UpdateData(ClientBindingModel model)
|
public void UpdateData(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logic.Update(model);
|
_logic.Update(model);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка обновления данных");
|
_logger.LogError(ex, "Ошибка обновления данных");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||||
|
Loading…
Reference in New Issue
Block a user