//select available modeule public ActionResult SelectModuleIndex(string UserID) { ApplicationDbContext context = new ApplicationDbContext(); DisplayManagerRoleDelete ObjRole = new DisplayManagerRoleDelete(); ModuleSelectVM ObjS = new ModuleSelectVM(); var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context)); var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context)); ObjS.AllRoles = userManager.GetRoles(UserID); var LoggedUserID = User.Identity.GetUserId(); ObjS.BuildingUser = db.BuildingUser.Where(c => c.UserID == LoggedUserID).FirstOrDefault(); return View(ObjS); }
public ActionResult DeleteRole(string RoleName, string RoleID) { ApplicationDbContext context = new ApplicationDbContext(); DisplayManagerRoleDelete ObjRole = new DisplayManagerRoleDelete(); ObjRole.MyRoles = db.AspNetRoles.Where(c => c.Name.Equals(RoleName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context)); var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context)); // ObjRole.buildingmanager = db.ManagerBuilding.Where(c => c.UserID == c.Manager.ID).ToList(); List<Manager> list1 = new List<Manager>(); List<Buildings> ListBuilding = new List<Buildings>(); // find list all manager var objAllManager = db.Manager.ToList(); // loop through all manager foreach(var item in objAllManager) {//list of role that belong to the current user var ListofRoleName = userManager.GetRoles(item.AspNetUsers.Id).ToList(); //loop through all names foreach (var individualRoleName in ListofRoleName) {//check if the current role matches the role passed if (individualRoleName == RoleName) { //if match then load manager Manager ObjManager = new Manager(); ObjManager = db.Manager.Find(item.AspNetUsers.Id); //add manager to myManager List<> // ObjRole.MyManagers.Add(ObjManager); var objmb = db.ManagerBuilding.Where(c => c.UserID == item.AspNetUsers.Id).ToList(); foreach(var item2 in objmb) { ListBuilding.Add(item2.Buildings); } list1.Add(ObjManager); } } } ViewBag.Managers = list1; ViewBag.Buildings = ListBuilding; return View(ObjRole); }