diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs index 9df375c..31732c2 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs @@ -63,39 +63,41 @@ namespace PolyclinicDatabaseImplement.Models public CourseViewModel GetViewModel => new() { Id = Id, - CourseName = CourseName, - Price = Price, + DaysCount = DaysCount, + PillsPerDay = PillsPerDay, + Comment = Comment, + RecipeId = RecipeId, CourseDiagnoses = CourseDiagnoses }; public void UpdateDiagnoses(SecuritySystemDatabase context, CourseBindingModel model) { - var courseDiagnoses = context.CourseDiagnoses.Where(rec => rec.CourseId == model.Id).ToList(); - if (courseDiagnoses != null && courseDiagnoses.Count > 0) - { - // удалили те, которых нет в модели - context.CourseDiagnoses.RemoveRange(courseDiagnoses.Where(rec => !model.CourseDiagnoses.ContainsKey(rec.DiagnoseId))); - context.SaveChanges(); - // обновили количество у существующих записей - foreach (var updateDiagnose in courseDiagnoses) - { - updateDiagnose.Count = model.CourseDiagnoses[updateDiagnose.DiagnoseId].Item2; - model.CourseDiagnoses.Remove(updateDiagnose.DiagnoseId); - } - context.SaveChanges(); - } - var course = context.Courses.First(x => x.Id == Id); - foreach (var pc in model.CourseDiagnoses) - { - context.CourseDiagnoses.Add(new CourseDiagnose - { - Course = course, - Diagnose = context.Diagnoses.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 - }); - context.SaveChanges(); - } - _courseDiagnoses = null; + //var courseDiagnoses = context.CourseDiagnoses.Where(rec => rec.CourseId == model.Id).ToList(); + //if (courseDiagnoses != null && courseDiagnoses.Count > 0) + //{ + // // удалили те, которых нет в модели + // context.CourseDiagnoses.RemoveRange(courseDiagnoses.Where(rec => !model.CourseDiagnoses.ContainsKey(rec.DiagnoseId))); + // context.SaveChanges(); + // // обновили количество у существующих записей + // foreach (var updateDiagnose in courseDiagnoses) + // { + // updateDiagnose.Count = model.CourseDiagnoses[updateDiagnose.DiagnoseId].Item2; + // model.CourseDiagnoses.Remove(updateDiagnose.DiagnoseId); + // } + // context.SaveChanges(); + //} + //var course = context.Courses.First(x => x.Id == Id); + //foreach (var pc in model.CourseDiagnoses) + //{ + // context.CourseDiagnoses.Add(new CourseDiagnose + // { + // Course = course, + // Diagnose = context.Diagnoses.First(x => x.Id == pc.Key), + // Count = pc.Value.Item2 + // }); + // context.SaveChanges(); + //} + //_courseDiagnoses = null; } } }