Пример #1
0
        public async Task <bool> IsAdminAsync(string userId)

        {
            var includeParams = new IncludeStringConstants().UserRolePermissionIncludeArray.ToList();

            return(UserIsInPermission(await GetUserByIdAsync(userId, includeParams.ToArray()), nameof(PermissionEnum.Admin)));
        }
Пример #2
0
        public async Task <bool> IsAdminAsync()
        {
            var userId        = GetAuthorizedUserId(_httpContextAccessor.HttpContext.User);
            var includeParams = new IncludeStringConstants().UserRolePermissionIncludeArray.ToList();

            return(UserIsInPermission(await GetUserByIdAsync(userId, includeParams.ToArray()), nameof(PermissionEnum.Admin)));
        }
Пример #3
0
        public async Task <ApiResponse> GetAllAsync()
        {
            var includeParams = new IncludeStringConstants().RolePermissionIncludeList;

            includeParams.Add("Users.User");
            var role = await _roleService.FindBy(c => c.IsEditable, includeParams.ToArray()).ToListAsync().ConfigureAwait(false);

            var data = _mapper.Map <List <Role>, List <RoleGetData> >(role);

            return(new ApiResponse(data));
        }
Пример #4
0
        public async Task <bool> UserIsInPermissionAsync(string userId, string permissionName)
        {
            var includeParams = new IncludeStringConstants().UserRolePermissionIncludeArray.ToList();
            var user          = await GetUserByIdAsync(userId, includeParams.ToArray()).ConfigureAwait(false);

            var directivePermissions = user.DirectivePermissions.Select(c => c.Permission.Label).ToList();
            var userRole             = user.Roles.Select(c => c.Role).ToList();
            var permissions          = userRole.SelectMany(c => c.PermissionCategory.Select(e => $"{ e.PermissionCategoryPermission.Category.Label.ToLower()}_{ e.PermissionCategoryPermission.Permission.Label.ToLower()}")).ToList();

            return(directivePermissions.Any(c => c.Equals(permissionName, StringComparison.OrdinalIgnoreCase)) ||
                   permissions.Any(c => c.Equals(permissionName, StringComparison.OrdinalIgnoreCase)));
        }
Пример #5
0
        public async Task <ApiResponse> GetInfoAsync()
        {
            var includeParams = new IncludeStringConstants().UserRolePermissionIncludeArray.ToList();

            includeParams.Add("Detail");
            var item = await _userService.GetUserByNameAsync(User.Identity.Name, includeParams.ToArray()).ConfigureAwait(false);

            if (item != null)
            {
                return(new ApiResponse(_mapper.Map <User, UserGetData>(item), StatusCodes.Status200OK));
            }
            throw new ApiException(MessageBuilder.NotFound, StatusCodes.Status404NotFound);
        }
Пример #6
0
        public async Task <ApiResponse> GetAsync(string id)
        {
            var includeParams = new IncludeStringConstants().RolePermissionIncludeList;

            includeParams.Add("Users.User");
            var role = await _roleService.GetRoleByIdAsync(id, includeParams.ToArray()).ConfigureAwait(false);

            if (role != null)
            {
                var data = _mapper.Map <Role, RoleGetData>(role);
                return(new ApiResponse(data));
            }

            throw new ApiException(MessageBuilder.NotFound, StatusCodes.Status404NotFound);
        }
Пример #7
0
        public async Task <ApiResponse> UpdateAsync([FromBody] UserEditData data)
        {
            if (!ModelState.IsValid)
            {
                throw new ApiException(ModelState.AllErrors());
            }

            var includeParams = new IncludeStringConstants().UserRolePermissionIncludeArray.ToList();
            var user          = await _userService.GetUserByIdAsync(data.Id, includeParams.ToArray()).ConfigureAwait(false);

            if (user == null)
            {
                throw new ApiException(MessageBuilder.NotFound, StatusCodes.Status404NotFound);
            }

            //update
            _mapper.Map <UserEditData, User>(data, user);

            await _userService.UpdateAsync(user).ConfigureAwait(false);

            return(await GetAsync(user.Id).ConfigureAwait(false));
        }