public async Task EditRole(NewRole newRole) { List <Permission> perms = new List <Permission>(); if (newRole.Permissions != null) { foreach (NewPermission perm in newRole.Permissions) { perms.Add(new Permission() { Perm = (Permissions)perm.Code }); } } if (_unitOfWork.Role.GetByName(newRole.Name) != null) { Role role = _unitOfWork.Role.GetByName(newRole.Name); _unitOfWork.Permission.RemoveExistingPermissions(role); role.Permissions = perms; _unitOfWork.SaveChanges(); await Clients.Caller.ConfirmRoleEdit(true); } else { await Clients.Caller.ConfirmRoleEdit(false); } }
internal async Task <JsonResult> RolePermissionUpdate(NewRole newRole) { SqlConnection cn = null; try { cn = Connection.GetConnection(); SqlCommand sc = new SqlCommand("role_permission_change", cn) { CommandType = CommandType.StoredProcedure }; sc.Parameters.Add("@jsonOutput", SqlDbType.NVarChar, -1).Direction = ParameterDirection.Output; sc.Parameters.AddWithValue("@role_id", newRole.RoleId); sc.Parameters.AddWithValue("@page_permission_number", ConvertListToDataTable(newRole.PageId)); await sc.ExecuteNonQueryAsync().ConfigureAwait(false); string json = sc.Parameters["@jsonOutput"].Value.ToString(); sc.Dispose(); JArray arr = JArray.Parse(json); return(new JsonResult(arr)); } catch (Exception) { throw; } finally { Connection.CloseConnection(ref cn); } }
public ActionResult Create(NewRole newRole) { string Output = ""; ApplicationDbContext db = new ApplicationDbContext(); RoleManager <IdentityRole> RoleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db)); if (!RoleManager.RoleExists("Admins")) { IdentityResult Result = RoleManager.Create(new IdentityRole(newRole.Name)); if (Result.Succeeded) { Output = "the role created"; } else { int ErrorCount = Result.Errors.Count(); Output = "Errors is: " + Result.Errors.ToList()[0]; } } else { Output = "the roles exist"; } if (Output == "") { ModelState.AddModelError(string.Empty, "tesssst"); return(View(newRole)); } else { var Roles = context.Roles.ToList(); return(View("Index", Roles)); } }
public async Task <JsonResult> RolePermissionUpdate([FromBody] NewRole newRole) { try { return(await _roleLogic.RolePermissionUpdate(newRole).ConfigureAwait(false)); } catch (Exception ee) { return(await _roleLogic.SendRespose("False", ee.Message).ConfigureAwait(false)); } }
public bool Validate(bool create, User authorizedUser) { if (authorizedUser != null && authorizedUser.Id != Id) { return(authorizedUser.GetTeacher() != null && (NewRole.Equals("Teacher") || NewRole.Equals("Tutor"))); } bool updateProof = Email != null && Identifier != null && Name != null && !Identifier.Contains("&") && (NewPassword == null || !NewPassword.Contains("&")) && (NewRole == null || NewRole.Equals("Teacher") || NewRole.Equals("Tutor") || NewRole.Equals("Student")); bool createProof = updateProof && NewPassword != null && NewRole != null; return(create ? createProof : updateProof); }
public IHttpActionResult CreateRole(NewRole newRole) { if (newRole == null) { throw new ArgumentNullException("newRole"); } if (string.IsNullOrWhiteSpace(newRole.Name)) { throw new ArgumentException("Role name must be defined."); } Role role = mapperFactory.CreateRoleMapper().Map(identityManagementService.CreateRole(newRole.Name, newRole.Description, newRole.ExternalGroupName)); return(Ok(role)); }
public async Task CreateRole(NewRole newRole) { List <Permission> perms = new List <Permission>(); if (newRole.Permissions != null) { foreach (NewPermission perm in newRole.Permissions) { perms.Add(new Permission() { Perm = (Permissions)perm.Code }); } } if (newRole.Name.Length <= 2) { await Clients.Caller.ConfirmRoleCreation(RoleCreationError.NameTooShort); } else if (newRole.Name.Length >= 20) { await Clients.Caller.ConfirmRoleCreation(RoleCreationError.NameTooLong); } else if (_unitOfWork.Role.GetByName(newRole.Name) != null) { await Clients.Caller.ConfirmRoleCreation(RoleCreationError.NameTaken); } else { Role role = new Role() { Name = newRole.Name, Permissions = perms }; _unitOfWork.Role.Add(role); _unitOfWork.SaveChanges(); await Clients.Caller.ConfirmRoleCreation(RoleCreationError.Success); } }
public ActionResult Create() { NewRole newRole = new NewRole(); return(View(newRole)); }
public object Get(NewRole request) { return new ServiceResult<Role> { Success = true, Result = _roleManager.New(), Errors = new string[] { } }; }