From ac8618e3e5ffe1a1f168d30f66b9be3da0a8bb59 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Sat, 9 Mar 2024 09:52:08 +0400 Subject: [PATCH] BaseUpdate --- .../BusinessLogic/ShopLogic.cs | 1 + .../Implements/ShopStorage.cs | 2 +- .../Implements/ShopStorage.cs | 36 +------------------ SewingDresses/SewingDressesView/MainForm.cs | 12 +++---- 4 files changed, 8 insertions(+), 43 deletions(-) diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs index 0bae47f..cc6b010 100644 --- a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs @@ -161,6 +161,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic Id = curModel.Id, ShopName = curModel.ShopName, DateOpen = curModel.DateOpen, + MaxCount = curModel.MaxCount, Adress = curModel.Adress, ShopDresses = curModel.ShopDresses, }); diff --git a/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs b/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs index 2da86f4..19ef35a 100644 --- a/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs +++ b/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs @@ -83,7 +83,7 @@ namespace SewingDressesFileImplement.Implements { var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id); - if (dres == null || CheckAvailability(model.Id, count)) + if (dres == null || !CheckAvailability(model.Id, count)) { return false; } diff --git a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs index 1be6bfe..3e7fbe9 100644 --- a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs +++ b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs @@ -107,44 +107,10 @@ namespace SewingDressesListImplement.Implements public bool CheckAvailability(int dressId, int count) { - int store = _source.Shops.Select(x => x.ShopDresses.Select(y => (y.Value.Item1.Id == dressId ? y.Value.Item2 : 0)).Sum()).Sum(); - return store >= count; + return true; } public bool SellDresses(IDressModel model, int count) { - var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id); - - if (dres == null || CheckAvailability(model.Id, count)) - { - return false; - } - - for (int i = 0; i < _source.Shops.Count; i++) - { - var shop = _source.Shops[i]; - var dresses = shop.ShopDresses; - foreach( var dress in dresses.Where(x => x.Value.Item1.Id == dres.Id)) - { - var selling = Math.Min(dress.Value.Item2, count); - dresses[dress.Value.Item1.Id] = (dress.Value.Item1, dress.Value.Item2 - selling); - - count -= selling; - - if (count <= 0) - { - break; - } - } - shop.Update(new ShopBindingModel - { - Id = model.Id, - ShopName = shop.ShopName, - Adress = shop.Adress, - MaxCount = shop.MaxCount, - DateOpen = shop.DateOpen, - ShopDresses = dresses - }); - } return true; } } diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index 0f2d012..a7e3e67 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -90,15 +90,13 @@ namespace SewingDressesView { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Order №{id}. Change status on 'Ready'", - id); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + var dressId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressId"].Value); + var count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value); + _logger.LogInformation("Order №{id}. Change status on 'Ready'", id); try { - var operationResult = _orderLogic.FinishOrder(new - OrderBindingModel - { Id = id }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, DressId = dressId, Count = count }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");