From 2c2eec51fffd7680f64cf2b6089951ee23fc32cd Mon Sep 17 00:00:00 2001 From: Inohara Date: Mon, 24 Apr 2023 18:50:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D0=B5=D0=BC=D1=83=20=D1=82?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IceCreamShopDatabaseImplement/Models/Shop.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Models/Shop.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Models/Shop.cs index 7484a20..8143f85 100644 --- a/IceCreamShop/IceCreamShopDatabaseImplement/Models/Shop.cs +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Models/Shop.cs @@ -89,9 +89,12 @@ namespace IceCreamShopDatabaseImplement.Models if (iceCreams != null && iceCreams.Count > 0) { // удалили те, которых нет в модели - context.ShopIcecreams.RemoveRange(iceCreams.Where(rec => !model.ShopIceCreams.ContainsKey(rec.IceCreamId))); - context.SaveChanges(); - iceCreams = context.ShopIcecreams.Where(rec => rec.ShopId == model.Id).ToList(); + if (shopIcecreams != null && shopIcecreams.Count > 0) + { + context.ShopIcecreams + .RemoveRange(shopIcecreams + .Where(rec => !model.ShopIceCreams + .ContainsKey(rec.IceCreamId))); // обновили количество у существующих записей foreach (var updateIceCream in iceCreams) {