예제 #1
0
        private void ValidateUserListWithSearch(UserListRequestModel request)
        {
            if (request.IsNotSpecified())
            {
                throw new WebApiException(HttpStatusCode.BadRequest, UserErrorMessage.MissingUsersInformation);
            }
            if (request.SortByColumn.IsNotSpecified())
            {
                throw new WebApiException(HttpStatusCode.BadRequest, UserErrorMessage.MissingUsersInformation);
            }
            if (request.SortingDirection.IsNotSpecified())
            {
                throw new WebApiException(HttpStatusCode.BadRequest, UserErrorMessage.MissingUsersInformation);
            }
            if (request.OffsetStart < 0)
            {
                throw new WebApiException(HttpStatusCode.BadRequest, UserErrorMessage.MissingUsersInformation);
            }
            if (request.OffsetEnd.IsNotSpecified())
            {
                throw new WebApiException(HttpStatusCode.BadRequest, UserErrorMessage.MissingUsersInformation);
            }
            if (request.CurrentPage < 0)
            {
                throw new WebApiException(HttpStatusCode.BadRequest, UserErrorMessage.MissingUsersInformation);
            }
            if (request.SortingDirection != "asc" && request.SortingDirection != "desc")
            {
                throw new WebApiException(HttpStatusCode.BadRequest, UserErrorMessage.MissingUsersInformation);
            }

            // todo: kke: implement this logic!
            //List<string> allowedSortByColumns = new List<string> { "AuctionName", "AuctionStartingPrice", "AuctionStartDate", "AuctionEndDate" };
            //if (allowedSortByColumns.Contains(request.SortByColumn) == false) { throw new WebApiException(HttpStatusCode.BadRequest, AuctionErrorMessages.MissingAuctionsInformation); }
        }
예제 #2
0
        public IActionResult UpdateProfile([FromQuery] UserListRequestModel requestModel)
        {
            var result = _databaseService.Users
                         .Include(s => s.GroupToUser)
                         .ThenInclude(s => s.Group).AsSingleQuery();

            // 按用户名关键字匹配
            if (requestModel.Username?.Length > 0)
            {
                foreach (var c in requestModel.Username)
                {
                    result = result.Where(s => s.Username.Contains(c));
                }
            }

            // 按照 ID 筛选
            if (requestModel.Id?.Length >= 0)
            {
                result = result.Where(s => requestModel.Id.Contains(s.Id));
            }

            // 添加其他的搜索条件

            result = result.Skip(requestModel.Offset);
            result = result.Take(requestModel.Amount);

            return(Ok(new UserListResultModel(result, requestModel.Amount, requestModel.Offset)));
        }
예제 #3
0
        public async Task <IActionResult> GetUsers([FromQuery] UserListRequestModel model, DataMode mode = DataMode.Full)
        {
            var filters = Mapper.Map <UserListQueryModel>(model);

            var users = await _userService.GetItemsAsync(filters, mode);

            var totalCount = await _userService.CountAsync(filters);

            return(await GetListViewModel(users, model, totalCount));
        }
예제 #4
0
        public async Task <UserListResponseModel> ListWithSearchAsync(UserListRequestModel request)
        {
            ValidateUserListWithSearch(request);

            (int startFrom, int endAt) = Pagination.GetOffsetAndSize(request);

            int loggedInUserId = LoggedInUserId();

            UserListResponseModel response = new UserListResponseModel()
            {
                Users     = m_userRepository.ListWithSearch(startFrom, endAt, loggedInUserId).ToList(),
                ItemCount = await m_userRepository.GetTotalUserCountAsync(loggedInUserId).ConfigureAwait(true)
            };

            Pagination.PaginateResponse(ref response, TableItem.DefaultSize, request.CurrentPage);

            return(response);
        }
예제 #5
0
 public async Task <IActionResult> Search([FromQuery] UserListRequestModel request)
 {
     return(Ok(await _userService.ListWithSearchAsync(request).ConfigureAwait(true)));
 }