public static ICollection <AdminUserDisplayViewModel> GetUsers() { try { using (var db = new ApplicationDbContext()) { string admin_roleid = GetAdminRoleId(); var users = from u in db.Users select u; List <AdminUserDisplayViewModel> icollection = new List <AdminUserDisplayViewModel>(); AdminUserDisplayViewModel t; var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); foreach (var us in users) { t = new AdminUserDisplayViewModel(); t.Email = us.Email; t.UserName = us.UserName; if (userManager.GetRoles(us.Id).Contains("Admin")) { t.IsAdmin = true; } t.UserId = us.Id; icollection.Add(t); } return(icollection); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public ActionResult ChangeUserToAdminConfirmed(string username) { ApplicationUser user = UserRoles.GetUserByUserName(username); AdminUserDisplayViewModel u = new AdminUserDisplayViewModel(); u.Email = user.Email; u.UserName = user.UserName; u.UserId = user.Id; if (UserRoles.ChangeUserRole(username)) { return(RedirectToAction("Index")); } ModelState.AddModelError("", "User Name Does not exists"); return(View(u)); }
// Get: ChangeUserToAdmin // GET: Locations/Delete/5 public ActionResult ChangeUserToAdmin(string username) { if (username == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ApplicationUser user = UserRoles.GetUserByUserName(username); if (user == null) { return(HttpNotFound()); } AdminUserDisplayViewModel u = new AdminUserDisplayViewModel(); u.Email = user.Email; u.UserName = user.UserName; u.UserId = user.Id; return(View(u)); }