public UserList GetAllUsers() { UserList users = new UserList(); using (var db = new UserModelEntities()) { var query = db.AspNetUsers.Select(x => x).OrderBy(x => x.UserName); var userModels = query.ToList(); string roleId = ""; foreach (AspNetUser user in userModels) { try { roleId = db.AspNetUserRoles.Where(x => x.UserId == user.Id).First().RoleId; } catch (Exception) { roleId = null; } users.Users.Add(new User(user.UserName, user.Id, roleId)); } } return(users); }
public void DemoteAdminToUserById(string Id) { using (var db = new UserModelEntities()) { db.AspNetUserRoles.Remove(db.AspNetUserRoles.Where(x => x.UserId == Id).First()); db.SaveChanges(); } }
public string GetUserIdByName(string name) { string retVal = ""; using (var db = new UserModelEntities()) { retVal = db.AspNetUsers.Where(x => x.UserName == name).First().Id; } return(retVal); }
public void PromoteUserToAdminById(string Id) { using (var db = new UserModelEntities()) { db.AspNetUserRoles.Add(new AspNetUserRole() { UserId = Id, RoleId = "c8299935-2c18-49a9-9765-22431174bece" }); db.SaveChanges(); } }
public ActionResult LeaveForm() { UserDropdownEntities userDropdownEntities = new UserDropdownEntities(); UserModelEntities userModel = new UserModelEntities(); var getuserlist = userDropdownEntities.Dropdowns.ToList(); var getuser = userModel.Users.ToList(); SelectList LeaveRequest = new SelectList(getuserlist.Where(o => o.DropdownType == "LeaveRequest"), "DropdownName", "DropdownName"); SelectList Approver = new SelectList(getuser.Where(o => o.Userlevel == "Admin"), "Userid", "Email"); ViewBag.LeaveRequest = LeaveRequest; ViewBag.Approver = Approver; return(View()); }
public ActionResult UserList(int?i) { UserModelEntities db = new UserModelEntities(); return(View(db.Users.ToList().ToPagedList(i ?? 1, 3))); }