From 736bd45bbcabbea5959c92685d86720f25aecc3f Mon Sep 17 00:00:00 2001 From: ekallin Date: Mon, 8 Apr 2024 11:28:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D1=83=D0=BB=20=D1=80=D0=B5=D0=BA=D0=B2?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B0=20=D0=BB=D0=B0=D0=B1=D0=B0=202=20?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBarBusinessLogic/ShopLogic.cs | 2 +- SushiBarFileImplement/Implements/ShopStorage.cs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/SushiBarBusinessLogic/ShopLogic.cs b/SushiBarBusinessLogic/ShopLogic.cs index dbe1066..44202bb 100644 --- a/SushiBarBusinessLogic/ShopLogic.cs +++ b/SushiBarBusinessLogic/ShopLogic.cs @@ -103,7 +103,7 @@ namespace SushiBarBusinessLogic if (element.MaxCountSushis - countSushis < count) { _logger.LogWarning("В магазине не хватает места"); - throw new ArgumentOutOfRangeException("Не зватает места в магазинах, увы... кушать меньше надо ", nameof(countSushis)); + throw new ArgumentOutOfRangeException("Не зватает места в магазине, увы... кушать меньше надо ", nameof(countSushis)); } if (element.ShopSushis.TryGetValue(sushi.Id, out var samesushi)) { diff --git a/SushiBarFileImplement/Implements/ShopStorage.cs b/SushiBarFileImplement/Implements/ShopStorage.cs index 0de0470..c2bd26d 100644 --- a/SushiBarFileImplement/Implements/ShopStorage.cs +++ b/SushiBarFileImplement/Implements/ShopStorage.cs @@ -10,14 +10,17 @@ namespace SushiBarFileImplement.Implements public class ShopStorage : IShopStorage { private readonly DataFileSingleton _source; + public ShopStorage() { _source = DataFileSingleton.GetInstance(); } + public List GetFullList() { return _source.Shops.Select(x => x.GetViewModel).ToList(); } + public List GetFilteredList(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName)) @@ -27,6 +30,7 @@ namespace SushiBarFileImplement.Implements return _source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); } + public ShopViewModel? GetElement(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) @@ -35,6 +39,7 @@ namespace SushiBarFileImplement.Implements } return _source.Shops.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } + public ShopViewModel? Insert(ShopBindingModel model) { model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1; @@ -47,6 +52,7 @@ namespace SushiBarFileImplement.Implements _source.SaveShops(); return newShop.GetViewModel; } + public ShopViewModel? Update(ShopBindingModel model) { var component = _source.Shops.FirstOrDefault(x => x.Id == model.Id); @@ -58,6 +64,7 @@ namespace SushiBarFileImplement.Implements _source.SaveShops(); return component.GetViewModel; } + public ShopViewModel? Delete(ShopBindingModel model) { var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id); @@ -69,11 +76,14 @@ namespace SushiBarFileImplement.Implements } return null; } + public bool CheckCountSushi(ISushiModel model, int count) { - int store = _source.Shops.Select(x => x.ShopSushis.Select(y => (y.Value.Item1.Id == model.Id ? y.Value.Item2 : 0)).Sum()).Sum(); + int store = _source.Shops.Select(x => x.ShopSushis.Select(y => + (y.Value.Item1.Id == model.Id ? y.Value.Item2 : 0)).Sum()).Sum(); return store >= count; } + public bool SellSushis(ISushiModel model, int count) { var sushi = _source.Sushis.FirstOrDefault(x => x.Id == model.Id); @@ -93,8 +103,6 @@ namespace SushiBarFileImplement.Implements if (count <= 0) { - //throw new ArgumentNullException("Такого количества суш нет, продать столько низя "); - break; } }