Exemplo n.º 1
0
        public async Task <NavigationModel <UserModel> > GetUsersAsync(UserFiltrPaginSortModel model)
        {
            var users = await _userManager.Users.
                        Where(n => EF.Functions.Like(n.Id.ToString(), $"%{model.Id}%") &&
                              EF.Functions.Like(n.LastName, $"%{model.LastName}%") &&
                              EF.Functions.Like(n.LastName, $"%{model.LastName}%") &&
                              (n.IsBlocked == model.IsBlocked || model.IsBlocked == null))
                        .OrderBy(model.PropertyForSort, model.IsAscending).Skip((model.CurrentPage - 1) * model.PageSize).Take(model.PageSize).ToListAsync();

            if (!users.Any())
            {
                throw new CustomExeption(Constants.Error.NO_USER_THIS_CONDITIONS,
                                         StatusCodes.Status400BadRequest);
            }

            int usersCount = await _userManager.Users.
                             Where(n => EF.Functions.Like(n.Id.ToString(), $"%{model.Id}%") &&
                                   EF.Functions.Like(n.LastName, $"%{model.LastName}%") &&
                                   EF.Functions.Like(n.LastName, $"%{model.LastName}%") &&
                                   (n.IsBlocked == model.IsBlocked || model.IsBlocked == null)).CountAsync();

            var userModels = _mapper.Map <IEnumerable <UserModel> >(users).ToList();

            PaginatedPageModel          paginatedPage = new PaginatedPageModel(usersCount, model.CurrentPage, model.PageSize);
            NavigationModel <UserModel> navigation    = new NavigationModel <UserModel>
            {
                PageModel    = paginatedPage,
                EntityModels = userModels
            };

            return(navigation);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetUsers(UserFiltrPaginSortModel model)
        {
            var result = await _userService.GetUsersAsync(model);

            return(Ok(result));
        }