--
This commit is contained in:
parent
ccef292353
commit
0a16389cb0
@ -4,6 +4,7 @@ using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -24,7 +25,7 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
||||
}
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList.Id:{Id} ", model?.Id);
|
||||
_logger.LogInformation("ReadList.OrderId:{Id} ", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() :
|
||||
_orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
@ -54,34 +55,59 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed. Order Status incorrect.");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Принят;
|
||||
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
model.Status = OrderStatus.Неизвестен;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool Update(OrderBindingModel model)
|
||||
public bool StatusUpdate(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if(model.Status + 1 > OrderStatus.Выдан)
|
||||
{
|
||||
_logger.LogWarning("Status update: operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
model.Status += 1;
|
||||
if(model.Status == OrderStatus.Выдан)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(OrderBindingModel model)
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_orderStorage.Delete(model) == null)
|
||||
return StatusUpdate(model);
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
return StatusUpdate(model);
|
||||
}
|
||||
return true;
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
@ -92,15 +118,21 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Component.Id: {Id}", model.Id);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||
if (model.WorkId < 0)
|
||||
{
|
||||
WorkName = model.WorkName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WorkId));
|
||||
}
|
||||
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new InvalidOperationException("Работа с таким названием уже есть");
|
||||
}
|
||||
throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
|
||||
}
|
||||
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user