public ActionResult DeleteUserFromRole([DataSourceRequest]DataSourceRequest request, string id, DetailModelType model) { var user = this.Data.Users.GetById(model.UserId); var role = user.Roles.FirstOrDefault(r => r.RoleId == id); user.Roles.Remove(role); this.Data.SaveChanges(); return this.Json(ModelState.ToDataSourceResult()); }
public ActionResult AddUserToRole([DataSourceRequest]DataSourceRequest request, string id, string userId) { var user = this.Data.Users.GetById(userId); var role = this.Data.Roles.All().FirstOrDefault(r => r.Id == id); user.Roles.Add(new IdentityUserRole { RoleId = role.Id, UserId = userId }); this.Data.SaveChanges(); var result = new UserInRoleAdministrationViewModel { UserId = user.Id, UserName = user.UserName, FirstName = user.UserSettings.FirstName, LastName = user.UserSettings.LastName, Email = user.Email }; return this.Json(new[] { result }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet); }
public ActionResult DeleteUserFromRole([DataSourceRequest] DataSourceRequest request, string id, DetailModelType model) { var user = this.Data.Users.GetById(model.UserId); var roleStore = new RoleStore <IdentityRole>(); var roleManager = new RoleManager <IdentityRole>(roleStore); var role = roleManager.Roles.FirstOrDefault(r => r.Id == id); if (role != null && role.Name == GlobalConstants.LecturerRoleName) { this.Data.LecturersInContests.Delete(x => x.LecturerId == model.UserId); this.Data.LecturersInContestCategories.Delete(x => x.LecturerId == model.UserId); } var userRole = user.Roles.FirstOrDefault(r => r.RoleId == id); user.Roles.Remove(userRole); this.Data.SaveChanges(); return(this.Json(this.ModelState.ToDataSourceResult())); }
public ActionResult DeleteUserFromRole([DataSourceRequest] DataSourceRequest request, string id, DetailModelType model) { var user = this.Data.Users.GetById(model.UserId); var role = user.Roles.FirstOrDefault(r => r.RoleId == id); user.Roles.Remove(role); this.Data.SaveChanges(); return(this.Json(this.ModelState.ToDataSourceResult())); }