public ActionResult AssignSelected(StudntsSelectionViewModel model, long Id) { var manager = db.Managers.Find(User.Identity.GetUserId().ToList()); var parent = manager.school.Parents.ToList().Find(p => p.Id == Id); var selectedIds = model.getSelectedIds(); var selectedStudents = (from x in manager.school.Students where selectedIds.Contains(x.Id) select x); foreach (var student in selectedStudents) { student.parent = parent; } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Assign() { string userId = User.Identity.GetUserId(); var manager = db.Managers.Find(userId); var students = manager.school.Students.ToList(); var model = new StudntsSelectionViewModel(); foreach (var student in students) { var editorViewModel = new SelectStudntEditorViewModel() { Id = student.Id, Name = student.ApplicationUser.fullName, idNo = student.idNo, grade = student.enrollment.grade.ToString() + student.enrollment.group, Selected = false }; model.Students.Add(editorViewModel); } return(View(model)); }