From 904ba78dde35d6da5e4548e1ee27d0903d0d694f Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Thu, 18 May 2023 21:49:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D1=82=D1=8C=D1=8F=20=D1=83?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D1=91=D0=BD=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.=20=D0=A4?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=20=D0=BA=D0=BE=D0=BC=D0=B8=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 13 +++++++++---- .../ConfectioneryDataBaseImplement/Models/Shop.cs | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Confectionery/ConfectioneryDataBaseImplement/Implements/ShopStorage.cs b/Confectionery/ConfectioneryDataBaseImplement/Implements/ShopStorage.cs index f0e52b0..cd84e39 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Implements/ShopStorage.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Implements/ShopStorage.cs @@ -4,6 +4,7 @@ using ConfectioneryContracts.StoragesContracts; using ConfectioneryContracts.ViewModels; using ConfectioneryDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; +using System.Transactions; using System; using System.Collections.Generic; using System.Linq; @@ -126,8 +127,7 @@ namespace ConfectioneryDataBaseImplement.Implements shop.ShopPastries.Add(pastryId, (pastry, count)); } shop.RemapPastries(context); - transaction.Commit(); - return true; + count = 0; } else { @@ -136,18 +136,23 @@ namespace ConfectioneryDataBaseImplement.Implements if (shop.ShopPastries.TryGetValue(pastryId, out var pastryCount)) { var shopPastry = shop.ShopPastries[pastryId]; - shopPastry.Item2 = pastryCount.Item2 + count; + shopPastry.Item2 = pastryCount.Item2 + freeShopSpace; shop.ShopPastries[pastryId] = shopPastry; } else { Pastry pastry = context.Pastrys.First(x => x.Id == pastryId); - shop.ShopPastries.Add(pastryId, (pastry, count)); + shop.ShopPastries.Add(pastryId, (pastry, freeShopSpace)); } shop.RemapPastries(context); } } } + if (count == 0) + { + transaction.Commit(); + return true; + } transaction.Rollback(); return false; } diff --git a/Confectionery/ConfectioneryDataBaseImplement/Models/Shop.cs b/Confectionery/ConfectioneryDataBaseImplement/Models/Shop.cs index e90d635..a5999c1 100644 --- a/Confectionery/ConfectioneryDataBaseImplement/Models/Shop.cs +++ b/Confectionery/ConfectioneryDataBaseImplement/Models/Shop.cs @@ -67,8 +67,9 @@ namespace ConfectioneryDataBaseImplement.Models public void UpdatePastries(ConfectioneryDatabase context, ShopBindingModel model) { + var list = context.ShopPastries.ToList(); var shopPastries = context.ShopPastries.Where(rec => rec.ShopId == model.Id).ToList(); - if (shopPastries != null && shopPastries.Count > 0) + if (shopPastries != null) { // удалили те, которых нет в модели context.ShopPastries.RemoveRange(shopPastries.Where(rec => !model.ShopPastries.ContainsKey(rec.PastryId)));