Exemplo n.º 1
0
        public async Task <IActionResult> GetUsers([FromQuery] UserAccountFilterModel filterModel,
                                                   int count = 10, int page = 1)
        {
            var result = await _accountService.GetUsers(page, count, filterModel);

            return(ApiResponder.RespondSuccess(result, null, result.GetPaginationData()));
        }
Exemplo n.º 2
0
        public async Task <CustomList <UserInformationModel> > GetUsers(int page, int count, UserAccountFilterModel filterModel)
        {
            var startAt = (page - 1) * count;
            var users   = await _context.Users
                          .Where(u => u.FullName.Contains(filterModel.Name, StringComparison.InvariantCultureIgnoreCase) &&
                                 u.Email.Contains(filterModel.Email, StringComparison.InvariantCultureIgnoreCase))
                          .OrderByDescending(u => u.RegisteredDate).Skip(startAt).Take(count).ToListAsync();

            var totalCount = await _context.Users
                             .Where(u => u.FullName.Contains(filterModel.Name, StringComparison.InvariantCultureIgnoreCase) &&
                                    u.Email.Contains(filterModel.Email, StringComparison.InvariantCultureIgnoreCase))
                             .OrderByDescending(u => u.RegisteredDate).CountAsync();

            var totalPages = totalCount / count + (totalCount % count > 0 ? 1 : 0);

            var userReturnModels = _mapper.Map <List <User>, CustomList <UserInformationModel> >(users);

            userReturnModels.CurrentPage   = page;
            userReturnModels.TotalPages    = totalPages;
            userReturnModels.TotalItems    = totalCount;
            userReturnModels.IsListPartial = true;

            return(userReturnModels);
        }