diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/RepairStorage.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/RepairStorage.cs index ae234ac..dd9c37d 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/RepairStorage.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/RepairStorage.cs @@ -70,16 +70,16 @@ namespace CarRepairShopDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var product = context.Repairs.FirstOrDefault(rec => rec.Id == model.Id); - if (product == null) + var repair = context.Repairs.FirstOrDefault(rec => rec.Id == model.Id); + if (repair == null) { return null; } - product.Update(model); + repair.Update(model); context.SaveChanges(); - product.UpdateComponents(context, model); + repair.UpdateComponents(context, model); transaction.Commit(); - return product.GetViewModel; + return repair.GetViewModel; } catch { diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs index 01a8c4a..50495c0 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Repair.cs @@ -16,19 +16,19 @@ namespace CarRepairShopDatabaseImplement.Models [Required] public double Price { get; set; } - private Dictionary? _productComponents = null; + private Dictionary? _repairComponents = null; [NotMapped] public Dictionary RepairComponents { get { - if (_productComponents == null) + if (_repairComponents == null) { - _productComponents = Components + _repairComponents = Components .ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count)); } - return _productComponents; + return _repairComponents; } } @@ -69,31 +69,31 @@ namespace CarRepairShopDatabaseImplement.Models public void UpdateComponents(CarRepairShopDatabase context, RepairBindingModel model) { - var productComponents = context.RepairComponents.Where(rec => rec.RepairId == model.Id).ToList(); - if (productComponents != null && productComponents.Count > 0) + var repairComponents = context.RepairComponents.Where(rec => rec.RepairId == model.Id).ToList(); + if (repairComponents != null && repairComponents.Count > 0) { // удалили те, которых нет в модели - context.RepairComponents.RemoveRange(productComponents.Where(rec => !model.RepairComponents.ContainsKey(rec.ComponentId))); + context.RepairComponents.RemoveRange(repairComponents.Where(rec => !model.RepairComponents.ContainsKey(rec.ComponentId))); context.SaveChanges(); // обновили количество у существующих записей - foreach (var updateComponent in productComponents) + foreach (var updateComponent in repairComponents) { updateComponent.Count = model.RepairComponents[updateComponent.ComponentId].Item2; model.RepairComponents.Remove(updateComponent.ComponentId); } context.SaveChanges(); } - var product = context.Repairs.First(x => x.Id == Id); + var repair = context.Repairs.First(x => x.Id == Id); foreach (var pc in model.RepairComponents) { context.RepairComponents.Add(new RepairComponent { - Repair = product, + Repair = repair, Component = context.Components.First(x => x.Id == pc.Key), Count = pc.Value.Item2 }); context.SaveChanges(); } - _productComponents = null; + _repairComponents = null; } } } \ No newline at end of file