From 509b29b85dbf27951deb2162e4edbb0ffaa8c8b4 Mon Sep 17 00:00:00 2001 From: goldfest Date: Mon, 6 May 2024 13:12:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TravelCompany/TravelCompany/FormShop.cs | 1 - ...20240506091037_Initial-Create.Designer.cs} | 2 +- ...te.cs => 20240506091037_Initial-Create.cs} | 0 .../Models/Shop.cs | 24 +++++++------------ 4 files changed, 10 insertions(+), 17 deletions(-) rename TravelCompany/TravelCompanyDatabaseImplement/Migrations/{20240503064033_Initial-Create.Designer.cs => 20240506091037_Initial-Create.Designer.cs} (99%) rename TravelCompany/TravelCompanyDatabaseImplement/Migrations/{20240503064033_Initial-Create.cs => 20240506091037_Initial-Create.cs} (100%) diff --git a/TravelCompany/TravelCompany/FormShop.cs b/TravelCompany/TravelCompany/FormShop.cs index 282374c..137cf24 100644 --- a/TravelCompany/TravelCompany/FormShop.cs +++ b/TravelCompany/TravelCompany/FormShop.cs @@ -102,7 +102,6 @@ namespace TravelCompany.Forms Adress = textBoxAdress.Text, OpeningDate = dateTimeOpen.Value, TravelMaxCount = (int)numericUpTravelMaxCount.Value, - ShopTravels = null }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503064033_Initial-Create.Designer.cs b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240506091037_Initial-Create.Designer.cs similarity index 99% rename from TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503064033_Initial-Create.Designer.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240506091037_Initial-Create.Designer.cs index 010d5b3..bdb2a52 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503064033_Initial-Create.Designer.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240506091037_Initial-Create.Designer.cs @@ -12,7 +12,7 @@ using TravelCompanyDatabaseImplement; namespace TravelCompanyDatabaseImplement.Migrations { [DbContext(typeof(TravelCompanyDataBase))] - [Migration("20240503064033_Initial-Create")] + [Migration("20240506091037_Initial-Create")] partial class InitialCreate { /// diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503064033_Initial-Create.cs b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240506091037_Initial-Create.cs similarity index 100% rename from TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503064033_Initial-Create.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240506091037_Initial-Create.cs diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Shop.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Shop.cs index 3a912a5..4e85982 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Shop.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Shop.cs @@ -72,35 +72,29 @@ namespace TravelCompanyDatabaseImplement.Models ShopTravels = ShopTravels, TravelMaxCount = TravelMaxCount }; - public void UpdateTravels(TravelCompanyDataBase context, ShopBindingModel model) { - if (model.ShopTravels == null) - return; - var shopTravels = context.ShopTravels.Where(rec => - rec.ShopId == model.Id).ToList(); - if (shopTravels != null && shopTravels.Count > 0) + var ShopTravels = context.ShopTravels.Where(rec => rec.ShopId == model.Id).ToList(); + if (ShopTravels != null && ShopTravels.Count > 0) { - context.ShopTravels.RemoveRange(shopTravels.Where(rec -=> !model.ShopTravels.ContainsKey(rec.TravelId))); - + context.ShopTravels.RemoveRange(ShopTravels.Where(rec => !model.ShopTravels.ContainsKey(rec.TravelId))); context.SaveChanges(); - foreach (var updateTravel in shopTravels) + ShopTravels = context.ShopTravels.Where(rec => rec.ShopId == model.Id).ToList(); + foreach (var updateTravel in ShopTravels) { - updateTravel.Count = - model.ShopTravels[updateTravel.TravelId].Item2; + updateTravel.Count = model.ShopTravels[updateTravel.TravelId].Item2; model.ShopTravels.Remove(updateTravel.TravelId); } context.SaveChanges(); } var shop = context.Shops.First(x => x.Id == Id); - foreach (var pc in model.ShopTravels) + foreach (var ar in model.ShopTravels) { context.ShopTravels.Add(new ShopTravels { Shop = shop, - Travel = context.Travels.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 + Travel = context.Travels.First(x => x.Id == ar.Key), + Count = ar.Value.Item2 }); context.SaveChanges(); }