public ActionResult CreatePOST() { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var viewModel = new RoleCreateViewModel(); TryUpdateModel(viewModel); if(String.IsNullOrEmpty(viewModel.Name)) { ModelState.AddModelError("Name", T("Role name can't be empty")); } var role = _roleService.GetRoleByName(viewModel.Name); if (role != null) { ModelState.AddModelError("Name", T("Role with same name already exists")); } if (!ModelState.IsValid) { viewModel.FeaturePermissions = _roleService.GetInstalledPermissions(); return View(viewModel); } _roleService.CreateRole(viewModel.Name); foreach (string key in Request.Form.Keys) { if (key.StartsWith("Checkbox.") && Request.Form[key] == "true") { string permissionName = key.Substring("Checkbox.".Length); _roleService.CreatePermissionForRole(viewModel.Name, permissionName); } } return RedirectToAction("Index"); }
public ActionResult Create() { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var model = new RoleCreateViewModel { FeaturePermissions = _roleService.GetInstalledPermissions() }; return View(model); }