示例#1
0
        public async Task <IActionResult> RemovePermissionFromUser(
            UserRoleOrPermissionUpdateDto dto
            )
        {
            try
            {
                await _usersPermissionsService.DeletePermissionFromUserAsync(dto);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }
示例#2
0
        public async Task <IActionResult> AddPermissionToUser(
            UserRoleOrPermissionUpdateDto dto
            )
        {
            try
            {
                var responsePayload = await _usersPermissionsService.AddPermissionToUserAsync(dto);

                return(Ok(responsePayload));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ex.Message }));
            }
        }
示例#3
0
        public async Task DeleteRoleFromUserAsync(UserRoleOrPermissionUpdateDto dto)
        {
            var user =
                await _userRepository.GetByIdAsync(dto.UserId);

            if (user == null)
            {
                throw new ObjectNotFoundException("User not found.");
            }

            var userToRoleConnection =
                await(await _usersRolesRepository.GetAllAsync(d =>
                                                              d.User == user && d.Role.Id == dto.RoleOrPermissionId))
                .FirstOrDefaultAsync();

            if (userToRoleConnection == null)
            {
                throw new ObjectNotFoundException("User role not found.");
            }

            await _usersRolesRepository.RemoveAsync(userToRoleConnection);

            //return await UserService.GetUserAsync(removedRole.User.UserName);
        }
 public Task DeletePermissionFromUserAsync(UserRoleOrPermissionUpdateDto dto)
 {
     return(DeletePermissionFromUserAsync(dto.UserId, dto.RoleOrPermissionId));
 }
 public Task <UserPermissionReturnDto> AddPermissionToUserAsync(UserRoleOrPermissionUpdateDto dto)
 {
     return(AddPermissionToUserAsync(dto.UserId, dto.RoleOrPermissionId));
 }
示例#6
0
 public async Task <UserRoleReturnDto> AddRoleToUserAsync(UserRoleOrPermissionUpdateDto dto)
 {
     return(await AddRoleToUserAsync(dto.UserId, dto.RoleOrPermissionId));
 }