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 <NavigationModel <AuthorModel> > GetAsync(AuthorFiltrPagingSortModel model)
        {
            var authorFiltrPagingSortModelDAL = _mapper.Map <AuthorFiltrPagingSortModelDAL>(model);

            (IEnumerable <Author> authors, int count)authorsWithCount = await _authorRepository.GetAsync(authorFiltrPagingSortModelDAL);

            if (!authorsWithCount.authors.Any())
            {
                throw new CustomExeption(Constants.Error.NO_ANY_AUTHOR_IN_DB_WITH_THIS_CONDITIONS,
                                         StatusCodes.Status400BadRequest);
            }
            var authorModels = _mapper.Map <IEnumerable <AuthorModel> >(authorsWithCount.authors);

            PaginatedPageModel            paginatedPage = new PaginatedPageModel(authorsWithCount.count, model.CurrentPage, model.PageSize);
            NavigationModel <AuthorModel> result        = new NavigationModel <AuthorModel>
            {
                PageModel    = paginatedPage,
                EntityModels = authorModels
            };

            return(result);
        }
Exemplo n.º 3
0
        public async Task <NavigationModel <PrintingEditionModel> > GetAsync(EditionFiltrPaginSortModel model)
        {
            var editionFiltrPagingSortModelDAL = _mapper.Map <EditionFiltrPagingSortModelDAL>(model);

            (IEnumerable <PrintingEdition> editions, int count)editionsCount = await _printingEditionRepository.GetAsync(editionFiltrPagingSortModelDAL);

            if (!editionsCount.editions.Any())
            {
                throw new CustomExeption(Constants.Error.NO_ANY_EDITIONS_IN_DB_WITH_THIS_CONDITIONS,
                                         StatusCodes.Status400BadRequest);
            }

            var editionModels = _mapper.Map <IEnumerable <PrintingEditionModel> > (editionsCount.count);

            PaginatedPageModel paginatedPage = new PaginatedPageModel(editionsCount.count, model.CurrentPage, model.PageSize);
            NavigationModel <PrintingEditionModel> navigation = new NavigationModel <PrintingEditionModel>
            {
                PageModel    = paginatedPage,
                EntityModels = editionModels
            };

            return(navigation);
        }