Доработка OrderLogic

This commit is contained in:
Ino 2023-01-30 15:29:32 +04:00
parent cb970c1ad7
commit aab26ccc29
2 changed files with 39 additions and 12 deletions

View File

@ -44,33 +44,41 @@ namespace IceCreamBusinessLogic.BusinessLogics
public bool DeliveryOrder(OrderBindingModel model) public bool DeliveryOrder(OrderBindingModel model)
{ {
throw new NotImplementedException(); return SetNewStatus(model, OrderStatus.Готов);
} }
public bool FinishOrder(OrderBindingModel model) public bool FinishOrder(OrderBindingModel model)
{ {
throw new NotImplementedException(); return SetNewStatus(model, OrderStatus.Выдан);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
throw new NotImplementedException();
} }
public bool TakeOrderInWork(OrderBindingModel model) public bool TakeOrderInWork(OrderBindingModel model)
{ {
throw new NotImplementedException(); return SetNewStatus(model, OrderStatus.Выполняется);
} }
private void CheckModel(OrderBindingModel model, bool withParams = true) public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. OrderID:{IceCreamName}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(OrderBindingModel model)
{ {
if (model == null) if (model == null)
{ {
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
if (!withParams) if (model.Id < 0)
{ {
return; throw new ArgumentNullException("Некорректный идентификатор заказа", nameof(model.Id));
} }
if (model.IceCreamId < 0) if (model.IceCreamId < 0)
{ {
@ -86,5 +94,24 @@ namespace IceCreamBusinessLogic.BusinessLogics
} }
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId); _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. DocumentId: { DocumentId}", model.Id, model.Sum, model.IceCreamId);
} }
public bool SetNewStatus(OrderBindingModel model, OrderStatus newStatus)
{
CheckModel(model);
if (model.Status + 1 != newStatus)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
} }
} }

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.3.32922.545 VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShop", "IceCreamShop\IceCreamShop.csproj", "{B91C88F0-28AC-47D1-8DDE-B5275C08CAC2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShopView", "IceCreamShop\IceCreamShopView.csproj", "{B91C88F0-28AC-47D1-8DDE-B5275C08CAC2}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShopDataModels", "IceCreamShopDataModels\IceCreamShopDataModels.csproj", "{998D2482-F931-4FEF-86E9-C21D6757B73A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShopDataModels", "IceCreamShopDataModels\IceCreamShopDataModels.csproj", "{998D2482-F931-4FEF-86E9-C21D6757B73A}"
EndProject EndProject