public JsonResponse Add(string roleName) { if (!Security.IsAuthorizedTo(Rights.CreateNewRoles)) { return GetNotAuthorized(); } else if (Utils.StringIsNullOrWhitespace(roleName)) { return new JsonResponse() { Message = Resources.labels.roleNameIsRequired }; } else if (Roles.RoleExists(roleName)) { return new JsonResponse() { Message = string.Format(Resources.labels.roleAlreadyExists, roleName) }; } else { var response = new JsonResponse(); try { Roles.CreateRole(roleName); response.Success = true; response.Message = string.Format(Resources.labels.roleHasBeenCreated, roleName); } catch (Exception ex) { Utils.Log(string.Format("Roles.AddRole: {0}", ex.Message)); response.Success = false; response.Message = string.Format(Resources.labels.couldNotCreateRole, roleName); } return response; } }
/// <summary> /// Initializes a new instance of the <see cref = "Comments" /> class. /// </summary> public Comments() { this.response = new JsonResponse(); }
public JsonResponse GetRoleRights(string roleName) { if (!Security.IsAuthorizedTo(Rights.EditRoles)) { return GetNotAuthorized(); } else if (Utils.StringIsNullOrWhitespace(roleName)) { return new JsonResponse() { Message = Resources.labels.roleNameArgumentNull }; } IEnumerable<Right> roleRights = Right.GetRights(roleName); var response = new JsonResponse() { Success = true, Data = string.Join("|", roleRights.Select(r => r.DisplayName).ToArray()) }; return response; }
public JsonResponse GetDefaultRoleRights(string roleName) { if (!Security.IsAuthorizedTo(Rights.EditRoles)) { return GetNotAuthorized(); } else if (Utils.StringIsNullOrWhitespace(roleName)) { return new JsonResponse() { Message = Resources.labels.roleNameArgumentNull }; } List<Rights> defaultRights = Right.GetDefaultRights(roleName); var response = new JsonResponse() { Success = true, Data = string.Join("|", defaultRights.Select(r => Utils.FormatIdentifierForDisplay(r.ToString())).ToArray()) }; return response; }
public JsonResponse Edit(string id, string bg, string[] vals) { if (!Security.IsAuthorizedTo(Rights.EditRoles)) { return GetNotAuthorized(); } else if (Utils.StringIsNullOrWhitespace(id)) { return new JsonResponse() { Message = Resources.labels.idArgumentNull }; } else if (vals == null) { return new JsonResponse() { Message = Resources.labels.valsArgumentNull }; } else if (vals.Length == 0 || Utils.StringIsNullOrWhitespace(vals[0])) { return new JsonResponse() { Message = Resources.labels.roleNameIsRequired }; } var response = new JsonResponse(); try { Right.OnRenamingRole(id, vals[0]); string[] usersInRole = Roles.GetUsersInRole(id); if (usersInRole.Length > 0) { Roles.RemoveUsersFromRoles(usersInRole, new string[] { id }); } Roles.DeleteRole(id); Roles.CreateRole(vals[0]); if (usersInRole.Length > 0) { Roles.AddUsersToRoles(usersInRole, new string[] { vals[0] }); } Right.RefreshAllRights(); response.Success = true; response.Message = string.Format(Resources.labels.roleUpdatedFromTo, id, vals[0]); } catch (Exception ex) { Utils.Log(string.Format("Roles.UpdateRole: {0}", ex.Message)); response.Message = string.Format(Resources.labels.couldNotUpdateRole, vals[0]); } return response; }
/// <summary> /// Initializes a new instance of the <see cref="Profile"/> class. /// </summary> public Profile() { this.response = new JsonResponse(); }
/// <summary> /// Initializes a new instance of the <see cref="UserService"/> class. /// </summary> public UserService() { this.response = new JsonResponse(); }