diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs index 71826cc..5e93501 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Sushi.cs @@ -16,19 +16,19 @@ namespace SushiBarDatabaseImplement.Models [Required] public double Price { get; set; } - private Dictionary? _productIngredients = null; + private Dictionary? _sushiIngredients = null; [NotMapped] public Dictionary SushiIngredients { get { - if (_productIngredients == null) + if (_sushiIngredients == null) { - _productIngredients = Ingredients + _sushiIngredients = Ingredients .ToDictionary(recPC => recPC.IngredientId, recPC => (recPC.Ingredient as IIngredientModel, recPC.Count)); } - return _productIngredients; + return _sushiIngredients; } } @@ -68,31 +68,31 @@ namespace SushiBarDatabaseImplement.Models public void UpdateIngredients(SushiBarDatabase context, SushiBindingModel model) { - var productIngredients = context.SushiIngredients.Where(rec => rec.SushiId == model.Id).ToList(); - if (productIngredients != null && productIngredients.Count > 0) + var sushiIngredients = context.SushiIngredients.Where(rec => rec.SushiId == model.Id).ToList(); + if (sushiIngredients != null && sushiIngredients.Count > 0) { // удалили те, которых нет в модели - context.SushiIngredients.RemoveRange(productIngredients.Where(rec => !model.SushiIngredients.ContainsKey(rec.IngredientId))); + context.SushiIngredients.RemoveRange(sushiIngredients.Where(rec => !model.SushiIngredients.ContainsKey(rec.IngredientId))); context.SaveChanges(); // обновили количество у существующих записей - foreach (var updateIngredient in productIngredients) + foreach (var updateIngredient in sushiIngredients) { updateIngredient.Count = model.SushiIngredients[updateIngredient.IngredientId].Item2; model.SushiIngredients.Remove(updateIngredient.IngredientId); } context.SaveChanges(); } - var product = context.SushiList.First(x => x.Id == Id); - foreach (var pc in model.SushiIngredients) + var sushi = context.SushiList.First(x => x.Id == Id); + foreach (var si in model.SushiIngredients) { context.SushiIngredients.Add(new SushiIngredient { - Sushi = product, - Ingredient = context.Ingredients.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 + Sushi = sushi, + Ingredient = context.Ingredients.First(x => x.Id == si.Key), + Count = si.Value.Item2 }); context.SaveChanges(); } - _productIngredients = null; + _sushiIngredients = null; } } } diff --git a/SushiBar/SushiBarFileImplement/Models/Sushi.cs b/SushiBar/SushiBarFileImplement/Models/Sushi.cs index d697e76..ec3518c 100644 --- a/SushiBar/SushiBarFileImplement/Models/Sushi.cs +++ b/SushiBar/SushiBarFileImplement/Models/Sushi.cs @@ -11,17 +11,17 @@ namespace SushiBarFileImplement.Models public string SushiName { get; private set; } = string.Empty; public double Price { get; private set; } public Dictionary Ingredients { get; private set; } = new(); - private Dictionary? _productIngredients = null; + private Dictionary? _sushiIngredients = null; public Dictionary SushiIngredients { get { - if (_productIngredients == null) + if (_sushiIngredients == null) { var source = DataFileSingleton.GetInstance(); - _productIngredients = Ingredients.ToDictionary(x => x.Key, y => ((source.Ingredients.FirstOrDefault(z => z.Id == y.Key) as IIngredientModel)!, y.Value)); + _sushiIngredients = Ingredients.ToDictionary(x => x.Key, y => ((source.Ingredients.FirstOrDefault(z => z.Id == y.Key) as IIngredientModel)!, y.Value)); } - return _productIngredients; + return _sushiIngredients; } } public static Sushi? Create(SushiBindingModel model) @@ -63,7 +63,7 @@ namespace SushiBarFileImplement.Models Price = model.Price; Ingredients = model.SushiIngredients.ToDictionary(x => x.Key, x => x.Value.Item2); - _productIngredients = null; + _sushiIngredients = null; } public SushiViewModel GetViewModel => new() {