From 49c182a59184a9611fd271252916fe6f78a40aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 6 Mar 2023 21:53:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BA=D0=BE=D1=81=D1=82=D1=8B=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectioneryDatabaseImplement/Shop.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ConfectioneryDatabaseImplement/Shop.cs b/ConfectioneryDatabaseImplement/Shop.cs index 190e58d..bd87290 100644 --- a/ConfectioneryDatabaseImplement/Shop.cs +++ b/ConfectioneryDatabaseImplement/Shop.cs @@ -106,12 +106,16 @@ namespace ConfectioneryDatabaseImplement.Models } } var shop = context.Shops.First(x => x.Id == model.Id); - shop.ShopPastries.AddRange(model.Pastries.Select(x => new ShopPastry - { - Pastry = context.Pastries.First(y => y.Id == x.Key), - Count = x.Value.Item2, - }).Except(shopPastries ?? new())); - context.SaveChanges(); + foreach (var pc in model.Pastries) + { + context.PastryComponents.Add(new() + { + Pastry = context.Pastries.First(y => y.Id == pc.Key), + Count = pc.Value.Item2, + }); + context.SaveChanges(); + } + context.SaveChanges(); _cachedPastries = null; } }