PIbd-22. Katysheva N.E LabWork6 #10
@ -4,7 +4,7 @@ using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels.Enums;
|
||||
using PizzeriaDataModels.Enums;
|
||||
|
||||
namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
{
|
||||
@ -19,10 +19,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
|
||||
|
||||
CheckModel(model);
|
||||
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
@ -39,30 +39,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
return true;
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||
model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id);
|
||||
var element = _orderStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}",
|
||||
model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id);
|
||||
_logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
@ -90,10 +70,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
|
||||
var searchOrder = new OrderSearchModel { Id = model.Id };
|
||||
var order = _orderStorage.GetElement(searchOrder);
|
||||
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(order));
|
||||
@ -112,10 +92,6 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
}
|
||||
model.Status = status;
|
||||
|
||||
if (order.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = order.ImplementerId;
|
||||
}
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
@ -127,11 +103,11 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
|
||||
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
@ -156,10 +132,6 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate)
|
||||
{
|
||||
throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}");
|
||||
}
|
||||
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PizzaId: {PizzaId}. PizzaCount: {Count}", model.Id, model.Sum, model.PizzaId, model.Count);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user