public ActionResult Roles(RolesViewModel model) { foreach (var user in model.UnassignedUsers.Where(x => !x.TempRole.Equals(AwanaRoles.Unassigned))) { user.Role = user.TempRole; Email.EmailHelper.SendEmail("Grace Church Awana Account Registration Approved", "Your account's registration has been approved and you may now login at the Grace Church Kelseyville Awana web site.", user.EmailAddress); } foreach (var user in model.AssignedUsers.Where(x => !x.Role.Equals(x.TempRole))) { user.Role = user.TempRole; } return RedirectToAction("Roles"); }
public ActionResult Roles() { //Requires admin privilege if (!User.IsInRole(AwanaRoles.Admin.ToString())) { return RedirectToAction("Index", "Home"); } var unassignedUsers = new List<ApplicationUser>(); var assignedUsers = new List<ApplicationUser>(); using (var context = new ApplicationDbContext()) { foreach (var user in context.Users) { if (user.Role.Equals(AwanaRoles.Unassigned)) { unassignedUsers.Add(user); } else { assignedUsers.Add(user); } } } var model = new RolesViewModel { UnassignedUsers = unassignedUsers.ToArray(), AssignedUsers = assignedUsers.ToArray() }; return View(model); }