diff --git a/MotorPlant/MotorPlantBusinessLogic/OrderLogic.cs b/MotorPlant/MotorPlantBusinessLogic/OrderLogic.cs index 3d3b955..4a36a77 100644 --- a/MotorPlant/MotorPlantBusinessLogic/OrderLogic.cs +++ b/MotorPlant/MotorPlantBusinessLogic/OrderLogic.cs @@ -13,14 +13,12 @@ namespace MotorPlantBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; private readonly IShopStorage _shopStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) { _logger = logger; _orderStorage = orderStorage; _shopStorage = shopStorage; } - public List? 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 diff --git a/MotorPlant/MotorPlantBusinessLogic/ShopLogic.cs b/MotorPlant/MotorPlantBusinessLogic/ShopLogic.cs index 640cb25..114fef4 100644 --- a/MotorPlant/MotorPlantBusinessLogic/ShopLogic.cs +++ b/MotorPlant/MotorPlantBusinessLogic/ShopLogic.cs @@ -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) diff --git a/MotorPlant/MotorPlantFileImplement/Shop.cs b/MotorPlant/MotorPlantFileImplement/Shop.cs index 4dfddf6..344360d 100644 --- a/MotorPlant/MotorPlantFileImplement/Shop.cs +++ b/MotorPlant/MotorPlantFileImplement/Shop.cs @@ -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; diff --git a/MotorPlant/MotorPlantListImplement/Shop.cs b/MotorPlant/MotorPlantListImplement/Shop.cs index 3ec70c1..b6f9455 100644 --- a/MotorPlant/MotorPlantListImplement/Shop.cs +++ b/MotorPlant/MotorPlantListImplement/Shop.cs @@ -17,6 +17,7 @@ namespace MotorPlantListImplement.Models public DateTime OpeningDate { get; private set; } public Dictionary ShopEngines { get; private set; } = new(); public int EngineMaxCount { get; private set; } + public static Shop? Create(ShopBindingModel? model) { if (model == null) diff --git a/MotorPlant/MotorPlantView/FormSellTravels.Designer.cs b/MotorPlant/MotorPlantView/FormSellEngines.Designer.cs similarity index 100% rename from MotorPlant/MotorPlantView/FormSellTravels.Designer.cs rename to MotorPlant/MotorPlantView/FormSellEngines.Designer.cs diff --git a/MotorPlant/MotorPlantView/FormSellTravels.cs b/MotorPlant/MotorPlantView/FormSellEngines.cs similarity index 100% rename from MotorPlant/MotorPlantView/FormSellTravels.cs rename to MotorPlant/MotorPlantView/FormSellEngines.cs diff --git a/MotorPlant/MotorPlantView/FormSellTravels.resx b/MotorPlant/MotorPlantView/FormSellEngines.resx similarity index 100% rename from MotorPlant/MotorPlantView/FormSellTravels.resx rename to MotorPlant/MotorPlantView/FormSellEngines.resx