public ActionResult CreatePOST() { if (!Services.Authorizer.Authorize(Permissions.ManageRoles, 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(Permissions.ManageRoles, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var model = new RoleCreateViewModel { FeaturePermissions = _roleService.GetInstalledPermissions() }; return View(model); }
public ActionResult CreatePOST() { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var viewModel = new RoleCreateViewModel(); try { UpdateModel(viewModel); //check if the role name already exists if (!_roleService.VerifyRoleUnicity(viewModel.Name)) { Services.Notifier.Error(T("Creating Role {0} failed: Role with same name already exists", viewModel.Name)); return RedirectToAction("Create"); } _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"); } catch (Exception exception) { this.Error(exception, T("Creating Role failed: {0}", exception.Message), Logger, Services.Notifier); return RedirectToAction("Create"); } }
public ActionResult CreatePOST() { if (!Services.Authorizer.Authorize(Permissions.ManageRoles, T("Not authorized to manage roles"))) return new HttpUnauthorizedResult(); var viewModel = new RoleCreateViewModel(); try { UpdateModel(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"); } catch (Exception exception) { Services.Notifier.Error("Creating Role failed: " + exception.Message); return RedirectToAction("Create"); } }