public ActionResult EditStudent(StudentViewModel vm) { var student = StudentRepository.GetStudentById(vm.StudentId); student.Name = vm.Name; student.Surname = vm.Surname; return PartialView("_editStudent", vm); }
public static StudentViewModel ToViewModel(this Student that) { var result = new StudentViewModel(); var marksDic = that.Marks.ToDictionary(a => a.Id, a => a); var markVmDic = that.Marks.ToDictionary(a => a.Id, a => new MarkViewModel()); var subjectDic = that.Subjects.ToDictionary(a => a.Id, a => a); var subjecVmtDic = that.Subjects.ToDictionary(a => a.Id, a => new SubjectViewModel()); var professorDic = that.Subjects.Select(a => a.Professor) .GroupBy(a => a.Id) .ToDictionary(a => a.Key, a => a.FirstOrDefault()); var professorVmDic = that.Subjects.Select(a => a.Professor) .GroupBy(a => a.Id) .ToDictionary(a => a.Key, a => new ProfessorViewModel()); var studentVmDic = new Dictionary<string, StudentViewModel> { [that.Id] = result }; var studentDic = new Dictionary<string, Student> { [that.Id] = that }; InitData(professorVmDic, studentVmDic, subjecVmtDic, markVmDic, professorDic, studentDic, subjectDic, marksDic); return result; }