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