public async Task <ActionResult> ApproveSelected(StudentsSelectionViewModel model) { string userId = User.Identity.GetUserId(); var teacher = db.Teachers.Find(userId); var selectedIds = model.getSelectedIds(); var selectedStudents = (from x in teacher.school.Students where selectedIds.Contains(x.Id) select x); foreach (var student in selectedStudents) { var user = db.Users.Find(student.Id); await this.UserManager.RemoveFromRoleAsync(user.Id, "GuestS"); await this.UserManager.AddToRoleAsync(user.Id, "Student"); student.active = true; student._date = DateTime.Now; if (user.Student.deactivatedStudent != null) { db.DeactivatedStudents.Remove(user.Student.deactivatedStudent); } } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Activate() { string userId = User.Identity.GetUserId(); var teacher = db.Teachers.Find(userId); var students = teacher.school.Students.ToList().FindAll(p => teacher.enrollments.Contains(p.enrollment) && p.active == false); var model = new StudentsSelectionViewModel(); foreach (var student in students) { var editorViewModel = new SelectStudentEditorViewModel() { Id = student.Id, Name = student.ApplicationUser.fullName, studNo = student.studNo, idNo = student.idNo, Selected = false }; model.Students.Add(editorViewModel); } return(View(model)); }