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; } }