public ActionResult Delete([DataSourceRequest] DataSourceRequest request, webpages_Role entry) { bool hasPermissions = sectionRpstry.GetPermission(sectionName, loggedUser.UserId, canDelete); if (hasPermissions) { try { if (entry.RoleName != ConfigurationManager.AppSettings["SuperAdminRoleName"] && entry.RoleName != ConfigurationManager.AppSettings["AdminRoleName"]) { Roles.DeleteRole(entry.RoleName); rpstry.Save(); } return(Json(new[] { entry }.ToDataSourceResult(request, ModelState))); } catch (Exception e) { return(Json(new[] { entry }.ToDataSourceResult(request, ModelState))); } } else { return(View("Error", "You do not have permissions to access this section.")); } }
// // GET: /Role/Delete/5 public ActionResult Delete(int id = 0) { webpages_Role webpages_role = db.Roles.Find(id); if (webpages_role == null) { return HttpNotFound(); } return View(webpages_role); }
public ActionResult Edit(webpages_Role webpages_role) { if (ModelState.IsValid) { db.Entry(webpages_role).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(webpages_role); }
public ActionResult Create(webpages_Role webpages_role) { if (ModelState.IsValid) { db.Roles.Add(webpages_role); db.SaveChanges(); return RedirectToAction("Index"); } return View(webpages_role); }
public ActionResult DeleteConfirmed(int id) { var users = from user in db.Users where user.RoleId == id select user; if (users.ToList().Count > 0)//有用户属于此角色不能删除 { ModelState.AddModelError("", "有用户属于此角色,无法删除!"); return View(db.Roles.Find(id)); } webpages_Role webpages_role = db.Roles.Find(id); db.Roles.Remove(webpages_role); db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult Create(webpages_Role entry) { bool hasPermissions = sectionRpstry.GetPermission(sectionName, loggedUser.UserId, canCreate); if (hasPermissions) { try { if (Roles.RoleExists(entry.RoleName)) { ModelState.AddModelError("", "This role already exists"); return(View(entry)); } else { Roles.CreateRole(entry.RoleName); #region Manage Permissions var allPermissions = Request.Form.AllKeys.Where(n => n.StartsWith("permission_")); rpstry.DeleteAllByRole(entry.RoleId); rpstry.Save(); foreach (var item in allPermissions) { var roleId = rpstry.GetAll().FirstOrDefault(d => d.RoleName == entry.RoleName).RoleId; int sectionId = Convert.ToInt32(item.ToString().Replace("permission_", "")); string[] permissiontypesIds = Request.Form.GetValues(item.ToString()); rpstry.ManagePermissions(roleId, sectionId, permissiontypesIds); } #endregion return(RedirectToAction("Index")); } } catch (Exception e) { ModelState.AddModelError("", ""); return(View(entry)); } } else { return(View("Error", "You do not have permissions to access this section.")); } }