From 50c0cdc17eb75b703eac7a8a10dfdb1fb78577ae Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:15:43 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=A8=D1=82=D1=83=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoragesContracts/ISushiStorage.cs | 1 - .../SushiBarFileImplement/Implements/SushiStorage.cs | 12 ++++-------- .../SushiBarListImplement/Implements/SushiStorage.cs | 5 ----- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs index f968fb1..38370ea 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -13,7 +13,6 @@ namespace SushiBarContracts.StoragesContracts SushiViewModel? Insert(SushiBindingModel model); SushiViewModel? Update(SushiBindingModel model); SushiViewModel? Delete(SushiBindingModel model); - bool HasSushi(ISushiModel model, int needCount); bool SellSushi(ISushiModel model, int count); } } diff --git a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs index 04399ba..522b360 100644 --- a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs @@ -72,17 +72,13 @@ namespace SushiBarFileImplement.Implements } return null; } - public bool HasSushi(ISushiModel sushi, int needCount) - { - var temp = source.Shops - .Select(x => x.ListSushi - .FirstOrDefault(x => x.Key == sushi.Id).Value.Item2).Sum(); - return temp >= needCount; - } public bool SellSushi(ISushiModel model, int count) { - if (!HasSushi(model, count)) + var temp = source.Shops + .Select(x => x.ListSushi + .FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum(); + if (temp < count) { return false; } diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index a57a5f8..a2bd782 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -100,11 +100,6 @@ namespace SushiBarListImplement.Implements return null; } - public bool HasSushi(ISushiModel model, int needCount) - { - throw new NotImplementedException(); - } - public bool SellSushi(ISushiModel model, int count) { throw new NotImplementedException(); From f997e6fc06f103f6d68778f4bacb1d48cd18ff18 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:20:57 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SushiBarFileImplement/Implements/OrderStorage.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index 0dbe30a..7d4b062 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -41,14 +41,9 @@ namespace SushiBarFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var sushi in source.ListSushi) - { - if (sushi.Id == order.SushiId) - { - viewModel.SushiName = sushi.SushiName; - break; - } - } + var sushi = source.ListSushi.FirstOrDefault(x => x.Id == order.SushiId); + if (sushi == null) return null; + viewModel.SushiName = sushi.SushiName; return viewModel; } public OrderViewModel? Insert(OrderBindingModel model) From 90dd93ef7ad6dfc41e85181cb0a648f5048cd646 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:20:57 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index 7d4b062..032b8d3 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -42,8 +42,7 @@ namespace SushiBarFileImplement.Implements { var viewModel = order.GetViewModel; var sushi = source.ListSushi.FirstOrDefault(x => x.Id == order.SushiId); - if (sushi == null) return null; - viewModel.SushiName = sushi.SushiName; + if (sushi != null) viewModel.SushiName = sushi.SushiName; return viewModel; } public OrderViewModel? Insert(OrderBindingModel model) From eb48ee2c52b236723fd4d8d9142cca8e96144cf8 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:35:15 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoragesContracts/ISushiStorage.cs | 2 -- .../Implements/SushiStorage.cs | 31 ------------------- 2 files changed, 33 deletions(-) diff --git a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs index 38370ea..ff49391 100644 --- a/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -1,7 +1,6 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.SearchModels; using SushiBarContracts.ViewModels; -using SushiBarDataModels.Models; namespace SushiBarContracts.StoragesContracts { @@ -13,6 +12,5 @@ namespace SushiBarContracts.StoragesContracts SushiViewModel? Insert(SushiBindingModel model); SushiViewModel? Update(SushiBindingModel model); SushiViewModel? Delete(SushiBindingModel model); - bool SellSushi(ISushiModel model, int count); } } diff --git a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs index 522b360..e5c4cab 100644 --- a/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/SushiStorage.cs @@ -72,36 +72,5 @@ namespace SushiBarFileImplement.Implements } return null; } - - public bool SellSushi(ISushiModel model, int count) - { - var temp = source.Shops - .Select(x => x.ListSushi - .FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum(); - if (temp < count) - { - return false; - } - - foreach (var shop in source.Shops.Where(x => x.ListSushi.ContainsKey(model.Id))) - { - if (shop.ListSushi[model.Id].Item2 < count) - { - shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, 0); - count -= shop.ListSushi[model.Id].Item2; - } - else - { - shop.ListSushi[model.Id] = (shop.ListSushi[model.Id].Item1, - shop.ListSushi[model.Id].Item2 - count); - count -= count; - } - if (count <= 0) - { - return true; - } - } - return true; - } } } From f1f1d11272b28c249567380aab3765488c6e11b1 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:35:15 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarListImplement/Implements/SushiStorage.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index a2bd782..750821d 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -99,10 +99,5 @@ namespace SushiBarListImplement.Implements } return null; } - - public bool SellSushi(ISushiModel model, int count) - { - throw new NotImplementedException(); - } } } \ No newline at end of file From f6e1a161e06e043378866d455470ff497e422527 Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 19 Mar 2023 12:35:15 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarListImplement/Implements/SushiStorage.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs index 750821d..d2878ca 100644 --- a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -2,7 +2,6 @@ using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; -using SushiBarDataModels.Models; using SushiBarListImplement.Models; namespace SushiBarListImplement.Implements