Сделал 2 сложную
This commit is contained in:
parent
5a3a87efb0
commit
ce22d61751
@ -13,14 +13,12 @@ namespace MotorPlantBusinessLogic.BusinessLogics
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
||||
@ -33,7 +31,6 @@ namespace MotorPlantBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -50,17 +47,14 @@ namespace MotorPlantBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ToNextStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return ToNextStatus(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel
|
||||
|
@ -116,8 +116,22 @@ namespace MotorPlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentException($"Поставка: Товар с id:{model.EngineId} не найденн");
|
||||
}
|
||||
if (shop.ShopEngines.Sum(kv => kv.Value.Item2) + model.Count > shop.EngineMaxCount)
|
||||
{
|
||||
throw new ArgumentException("Превышена максимальная вместимость магазина");
|
||||
}
|
||||
shop.ShopEngines.Add(model.EngineId, (Engine, model.Count));
|
||||
}
|
||||
_shopStorage.Update(new ShopBindingModel()
|
||||
{
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
Adress = shop.Adress,
|
||||
OpeningDate = shop.OpeningDate,
|
||||
ShopEngines = shop.ShopEngines,
|
||||
EngineMaxCount = shop.EngineMaxCount,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
|
@ -95,7 +95,6 @@ namespace MotorPlantFileImplement.Models
|
||||
x => new XElement("ShopEngine", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()),
|
||||
new XElement("EngineMaxCount", EngineMaxCount.ToString())
|
||||
);
|
||||
|
||||
public void EnginesUpdate()
|
||||
{
|
||||
_shopEngines = null;
|
||||
|
@ -17,6 +17,7 @@ namespace MotorPlantListImplement.Models
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
public Dictionary<int, (IEngineModel, int)> ShopEngines { get; private set; } = new();
|
||||
public int EngineMaxCount { get; private set; }
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
|
Loading…
Reference in New Issue
Block a user