Example #1
0
        //[Authorize(Policy = PermissionsList.PermissionsRolesAdd)]
        public async Task <IActionResult> Add([FromBody] RolePermissionModel permissionModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }


            Roles roleToChange = await _rolesRepository.GetRole(permissionModel.Role);

            var permissions = await _permissionRepository.GetAll();

            Permission permission = permissions.Where(p => p.Name == permissionModel.Permission)
                                    .FirstOrDefault();

            if (permission == null)
            {
                return(BadRequest());
            }

            List <RolesPermission> rolePermissions = roleToChange.Permissions.ToList();

            if (rolePermissions.Find(e => e.Permission.Name == permissionModel.Permission) != null)
            {
                return(BadRequest());
            }

            RolesPermission permissionToAdd = new RolesPermission()
            {
                Id         = Guid.NewGuid(),
                Permission = permission,
                Role       = roleToChange
            };

            _rolesPermissionRepository.Create(permissionToAdd);

            rolePermissions.Add(permissionToAdd);

            roleToChange.Permissions = rolePermissions;

            _rolesRepository.Update(roleToChange);

            return(Ok(String.Format("Added permission {0} to {1} role",
                                    permissionModel.Permission,
                                    permissionModel.Role)));
        }
        public async Task <IActionResult> GetRole(int?roleID)
        {
            try
            {
                var role = await roleRepository.GetRole(roleID);

                if (role == null)
                {
                    return(NotFound());
                }

                return(Ok(role));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #3
0
        public IActionResult Get(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            try
            {
                var post = _context.GetRole(id);

                if (post == null)
                {
                    return(NotFound());
                }

                return(Ok(post));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
 public RoleDTO GetRoleByName(string roleName)
 {
     return(ObjectHelpers.MapTo <RoleDTO>(RolesRepository.GetRole(roleName)));
 }
Example #5
0
 public void AssignPermissionToRole(string Permission, string Role)
 {
     AssignPermissionToRole(Permission, rolesRepository.GetRole(Role).Id);
 }
 public Task AssignRoleToAction(string ActionName, string RoleName)
 {
     return(AssignRoleToAction(ActionName, rolesRepository.GetRole(RoleName).Id));
 }