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(); }