public async Task <IActionResult> AddParents(EditParentsInputModel model) { model.StudentId = await CheckStudentId(this.TempData["studentId"]); await this.studentsService.AddParents(model); return(await Task.Run(() => this.RedirectToAction("Details", new { studentId = model.StudentId }))); }
public async Task <IActionResult> AddParents() { int studentId = await CheckStudentId(this.TempData["studentId"]); var parents = this.parentsService.GetAllForSelection(studentId).ToList(); var model = new EditParentsInputModel() { Parents = parents }; this.TempData.Keep("studentId"); return(await Task.Run(() => this.View("AddParents", model))); }
public async Task AddParents(EditParentsInputModel model) { var student = await this.db.Students.FirstOrDefaultAsync(x => x.Id == model.StudentId); var parentIds = model.Parents.Where(x => x.Selected).Select(x => x.Id).ToArray(); var parentsForStudent = this.db.Parents.Where(x => parentIds.Contains(x.Id)).ToArray(); foreach (var parent in parentsForStudent) { var link = new StudentParent { ParentId = parent.Id }; student.Parents.Add(link); } await this.db.SaveChangesAsync(); }