예제 #1
0
        private async Task <ActionResult <IEnumerable <T> > > GetUsersGeneric <T>(UsersParameters parameters)
        {
            bool isValidMapping = _mappingService.ValidMappingExistsFor <T, ApplicationUser>(parameters.OrderBy);

            parameters.SetSortingMappingSourceTypeName(typeof(T).Name);

            if (!isValidMapping)
            {
                return(this.GetGenericProblem(HttpStatusCode.BadRequest,
                                              $"Sorting using '{parameters.OrderBy}' is not possible"));
            }

            parameters.SetSortingMappingDestinationTypeName(nameof(ApplicationUser));

            var result = await _identityService.GetUsersFromRole(parameters);


            if (!result.Success)
            {
                return(this.GetGenericProblem(result));
            }

            this.SetPaginationInfoHeader(result.Object);

            return(Ok(_mapper.Map <IEnumerable <T> >(result.Object)));
        }
예제 #2
0
        public async Task <ActionResult <IEnumerable <UserApiKeyResponse> > > GetUserKeys(string userId, [FromQuery] PaginationAndSortingParameters parameters)
        {
            var param = _mapper.Map <UserKeysParameters>(parameters);

            param.UserId = userId;

            if (!_mappingService.ValidMappingExistsFor <UserApiKeyResponse, ApiKey>(param.OrderBy))
            {
                return(this.GetGenericProblem(HttpStatusCode.BadRequest, $"Sorting using '{param.OrderBy}' is not possible"));
            }

            param.SetSortingMappingSourceTypeName(nameof(UserApiKeyResponse));
            param.SetSortingMappingDestinationTypeName(nameof(ApiKey));


            var result = await _identityService.GetUserApiKeysAsync(param);

            if (!result.Success)
            {
                return(this.GetGenericProblem(result));
            }

            this.SetPaginationInfoHeader(result.Object);

            return(Ok(_mapper.Map <IEnumerable <UserApiKeyResponse> >(result.Object)));
        }