Ejemplo n.º 1
0
        public async Task <IActionResult> GetAsync(
            [FromQuery] AppointmentsFiltrationQuery query,
            [FromQuery] PaginationQuery paginationQuery)
        {
            var pagination = _mapper.Map <PaginationFilter>(paginationQuery);
            var filter     = _mapper.Map <AppointmentsFilter>(query);

            var appointments = await _appointmentService.GetAllAppointmentsAsync(filter, pagination);

            var appointmentsDto = _mapper.Map <IEnumerable <AppointmentDto> >(appointments);

            var totalCount = await _appointmentService.GetTotalCount(filter);

            var pagedResponse = new PagedResponse <AppointmentDto>(appointmentsDto, paginationQuery, totalCount);

            return(Ok(pagedResponse));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> GetDeletedProduct([FromUri] PaginationQuery paginationQuery)
        {
            try
            {
                IEnumerable <Purchase> purchases = await Task.FromResult(purchaseRepository.GetAllDeleted(
                                                                             paginationQuery.Skip, paginationQuery.Limit));

                return(new HttpJsonApiResult <IEnumerable <PurchaseViewModel> >(
                           PurchaseViewModel.GetAll(purchases),
                           Request,
                           HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(new HttpJsonApiResult <string>("Internal Server Error", Request, HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 3
0
        public virtual async Task <PagedResponse <TModel> > Get(TSearch search, PaginationQuery pagination)
        {
            var query = _context.Set <TDatabase>()
                        .AsNoTracking()
                        .AsQueryable();


            query = ApplyFilter(query, search);
            query = ApplyPagination(query, pagination);


            var list = await query.ToListAsync();

            var pagedResponse = await GetPagedResponse <TModel, TDatabase>(_mapper.Map <List <TModel> >(list), pagination);

            return(pagedResponse);
        }
        public async Task <IActionResult> Index(int page = 1, string search = null)
        {
            var filter = new NamirnicaSearchRequest()
            {
                Naziv = search
            };
            var paginationQuery = new PaginationQuery(page, 10);

            var response = await _restoranApi.GetNamirnicaAsync(filter, paginationQuery);

            var model = new NamirnicaPrikaz()
            {
                Content = response.Content,
                Search  = search
            };

            return(View(model));
        }
        public async Task <IActionResult> GetAuthors([FromQuery] PaginationQuery paginationQuery, [FromQuery] AuthorFilter filter)
        {
            var authorResponse = await _authorService.GetAuthorsAsync();

            if (paginationQuery is null || paginationQuery.PageSize < 1 || paginationQuery.PageNumber < 1)
            {
                return(Ok(new PagedResponse <AuthorModel>(authorResponse)));
            }

            authorResponse = await _authorService.GetAuthorsAsync(paginationQuery, filter);

            var paginationResponse = PaginationProvider.CreatePaginatedResponse(_uriService,
                                                                                $"api/{ControllerContext.ActionDescriptor.ControllerName}/{Constants.Routes.AUTHORS_GET_ALL_ROUTE}",
                                                                                paginationQuery, filter,
                                                                                authorResponse);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 6
0
        public override async Task <IHttpActionResult> Get([FromUri] PaginationQuery paginationQuery)
        {
            try
            {
                IEnumerable <Category> categories = await Task.FromResult(categoryRepository
                                                                          .GetAll(paginationQuery.Skip, paginationQuery.Limit));

                return(new HttpJsonApiResult <IEnumerable <CategoryViewModel> >(
                           CategoryViewModel.GetAll(categories),
                           Request,
                           HttpStatusCode.OK
                           ));
            }
            catch (Exception)
            {
                return(new HttpJsonApiResult <string>("Internal Server Error", Request, HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 7
0
        public virtual async Task <PagedResponse <TModel> > Get(TSearch search, PaginationQuery pagination)
        {
            var query = _context.Set <TDatabase>()
                        .AsNoTracking()
                        .AsQueryable();

            query = ApplyFilter(query, search);

            var skip = (pagination.PageNumber - 1) * pagination.PageSize;

            query = query.Skip(skip).Take(pagination.PageSize);

            var list = await query.ToListAsync();

            var pagedResponse = await GetPagedResponse(_mapper.Map <List <TModel> >(list), search, pagination);

            return(pagedResponse);
        }
        public Uri GetAllPostsUri(PaginationQuery pagination = null)
        {
            var uri = new Uri(_baseUri);

            if (pagination == null)
            {
                return(uri);
            }

            var modifieldUri = QueryHelpers.AddQueryString(_baseUri, new Dictionary <string, string>(
                                                               new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("pageNumber", pagination.PageNumber.ToString()),
                new KeyValuePair <string, string>("pageSize", pagination.PageSize.ToString())
            }));

            return(new Uri(modifieldUri));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Query([FromQuery] String[] fields    = null,
                                                [FromQuery] String[] values    = null,
                                                [FromQuery] String[] types     = null,
                                                [FromQuery] String[] operators = null,
                                                [FromQuery] PaginationQuery paginationQuery = null)
        {
            var parameters = GenerateSearchParameters(fields, values, types, operators);
            var pagination = _mapper.Map <PaginationFilter>(paginationQuery);
            var list       = await _repository.GetAllPageableAsync(pagination, parameters);

            if (pagination == null || pagination.PageNumber < 1 || pagination.PageSize < 1)
            {
                return(Ok(new PagedResponse <T>(list)));
            }
            var paginationResponse = PaginationHelpers.CreatePaginatedResponse(_uriService, pagination, list);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> GetDistricts(
            string countryTag,
            string provinceName,
            [FromQuery] PaginationQuery paginationQuery)
        {
            var pagination = _mapper.Map <PaginationParams>(paginationQuery);

            var result = await _locationService.GetDistrictsAsync(countryTag, provinceName, pagination);

            if (pagination == null || !pagination.IsValidPagination())
            {
                return(Ok(new PagedResponse <DistrictDto>(result)));
            }

            var paginatedResponse = PaginationHelpers.CreatePaginatedResponse(_uriGeneratorService, pagination, result);

            return(Ok(paginatedResponse));
        }
Ejemplo n.º 11
0
        public async Task <IHttpActionResult> ReadPurchasePrices([FromUri] PaginationQuery paginationQuery)
        {
            try
            {
                IEnumerable <Price> prices = await Task.FromResult(priceRepository.GetAll(
                                                                       PriceTypeEnum.Purchase, paginationQuery.Skip,
                                                                       paginationQuery.Limit));

                return(new HttpJsonApiResult <IEnumerable <PriceViewModel> >(
                           PriceViewModel.GetAll(prices),
                           Request,
                           HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(new HttpJsonApiResult <string>("Internal Server Error", Request, HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> GetAllOrders(
            [FromQuery] OrderFilterQuery filterQuery,
            [FromQuery] PaginationQuery paginationQuery)
        {
            int customerId = User.GetClaim <int>(ClaimTypes.NameIdentifier);

            var filter     = _mapper.Map <OrderFilterParams>(filterQuery);
            var pagination = _mapper.Map <PaginationParams>(paginationQuery);

            filter.CustomerId = customerId;

            var resultOrders = (await _orderService.GetAllOrdersAsync(filter, pagination)).ToArray();

            var paginationResponse =
                PaginationHelpers.CreatePaginatedQueryResponse(_uriGeneratorService, pagination, resultOrders, resultOrders.Count());

            return(Ok(paginationResponse));
        }
Ejemplo n.º 13
0
        public Uri GetAllAnnouncesUri(string path = "", PaginationQuery pagination = null, GetAllAnnouncesFilter announcesFilter = null)
        {
            var uriWithPath = $"{_baseUri}{path}/";

            var uri = new Uri(uriWithPath);

            if (pagination == null)
            {
                return(uri);
            }


            var modifiedUri = QueryHelpers.AddQueryString(uriWithPath, "pageNumber", pagination.PageNumber.ToString());

            modifiedUri = QueryHelpers.AddQueryString(modifiedUri, "pageSize", pagination.PageSize.ToString());
            AddFilterParameters(announcesFilter, ref modifiedUri);
            return(new Uri(modifiedUri));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> GetAll([FromQuery] GetAllPostsQuery query, [FromQuery] PaginationQuery paginationQuery)

        {
            var pagination = _mapper.Map <PaginationFilter>(paginationQuery);
            var filter     = _mapper.Map <GetAllPostsFilter>(query);
            var posts      = await _postService.GetPostsAsync(filter, pagination);

            var postsResponse = _mapper.Map <List <PostResponse> >(posts);

            if (pagination == null || pagination.PageNumber < 1 || pagination.PageSize < 1)
            {
                return(Ok(new PagedResponse <PostResponse>(postsResponse)));
            }

            var paginationResponse = PaginationHelpers.CreatePaginatedResponse(_uriService, pagination, postsResponse);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 15
0
        public static async Task <PaginatedResult <TOut> > GetPaginatedResult <TQuery, TOut>(
            PaginationQuery paginationQuery,
            IQueryable <TQuery> query,
            Func <IReadOnlyCollection <TQuery>, IEnumerable <TOut> > transform)
        {
            int?totalRecord = null;

            if (paginationQuery.IncludeCount)
            {
                totalRecord = await query.CountAsync();
            }

            var result = await query
                         .Skip((int)paginationQuery.ToSkip)
                         .Take((int)paginationQuery.PageSize)
                         .ToArrayAsync();

            return(new PaginatedResult <TOut>(paginationQuery, totalRecord, transform(result).ToArray()));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> GetEditions([FromQuery] PaginationQuery paginationQuery, [FromQuery] PrintingEditionFilter filter)
        {
            var editionsResponse = await _editionService.GetAllEditionsAsync();

            if (paginationQuery is null || paginationQuery.PageSize < 1 || paginationQuery.PageNumber < 1)
            {
                return(Ok(new PagedResponse <PrintingEditionModel>(editionsResponse)));
            }

            editionsResponse = await _editionService.GetAllEditionsAsync(paginationQuery, filter);

            var paginationResponse = PaginationProvider.CreatePaginatedResponse(_uriService,
                                                                                $"api/{ControllerContext.ActionDescriptor.ControllerName}/{Constants.Routes.EDITIONS_GET_ALL_ROUTE}",
                                                                                paginationQuery, filter,
                                                                                editionsResponse);


            return(Ok(paginationResponse));
        }
Ejemplo n.º 17
0
        private JToken CreateTopLevelLinks(int count, string id = null)
        {
            var result = new JObject();

            // to preserve back compatibility if Self is enabled, then we also render it. Or if TopSelf is enabled
            if (_resource.LinkType.HasFlag(LinkType.TopSelf) || _resource.LinkType.HasFlag(LinkType.Self))
            {
                if (id != null && !_baseUrl.AbsolutePath.EndsWith(id, StringComparison.InvariantCultureIgnoreCase))
                {
                    AddUrl(result, "self", _urlBuilder.BuildCanonicalPath(_resource, id));
                }
                else
                {
                    result.Add("self", _baseUrl.ToString());
                }
            }

            var queryStrings = new PaginationQuery(_paginationContext, _value);

            var left = _baseUrl.GetLeftPart(UriPartial.Path);

            if (queryStrings.FirstPage != null)
            {
                result["first"] = new Uri(left + queryStrings.FirstPage);
            }

            if (queryStrings.NextPage != null && count >= _paginationContext.PerPage)
            {
                result["next"] = new Uri(left + queryStrings.NextPage);
            }

            if (queryStrings.PreviousPage != null)
            {
                result["prev"] = new Uri(left + queryStrings.PreviousPage);
            }

            if (queryStrings.LastPage != null)
            {
                result["last"] = new Uri(left + queryStrings.LastPage);
            }

            return(result);
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> GetAll([FromQuery] string userId, [FromQuery] PaginationQuery paginationQuery)
        {
            var paginationFilter = new PaginationFilter
            {
                PageNumber = paginationQuery.PageNumber,
                PageSize   = paginationQuery.PageSize
            };

            var posts = await _postService.GetPostsAsync(userId, paginationFilter);

            if (paginationFilter == null || paginationFilter.PageNumber < 1 || paginationFilter.PageSize < 1)
            {
                return(Ok(new PagedResponse <Post>(posts)));
            }

            var paginationResponse = PaginationHelper.CreatePaginationResponse(_uriService, paginationFilter, posts);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery)
        {
            var pagination = _mapper.Map <PaginationFilter>(paginationQuery);

            var loggedUserId      = HttpContext.GetUserId();
            var rosterAccessModel = await _rosterAccessService.GetRosterAccessesByUserIdAsync(loggedUserId);

            var rosters         = _rosterService.GetRosters(rosterAccessModel, pagination);
            var rostersResponse = _mapper.Map <List <RosterResponse> >(rosters);

            if (pagination == null || pagination.PageNumber < 1 || pagination.PageSize < 1)
            {
                return(Ok(new PagedResponse <RosterResponse>(rostersResponse)));
            }

            var paginationResponse = PaginationHelper.CreatePaginatedResponse(_uriService, pagination, rostersResponse);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Get([FromQuery] PaginationQuery pagination, [FromQuery] SearchByDateDTO searchByDate)
        {
            if (searchByDate.EndingDate != null && searchByDate.StartingDate != null)
            {
                DateTime startDate;
                DateTime endDate;

                if (!DateTime.TryParse(searchByDate.StartingDate, out startDate))
                {
                    return(BadRequest("StartingDate tarih formatında değil"));
                }
                else if (!DateTime.TryParse(searchByDate.EndingDate, out endDate))
                {
                    return(BadRequest("EndingDate tarih formatında değil"));
                }

                if (startDate >= endDate)
                {
                    return(BadRequest("StartingDate, EndingDate tarihinden ileri bir tarih olamaz"));
                }
            }

            var paginationFilter = _mapper.Map <PaginationFilter>(pagination);
            var getallnews       = await _newsService.GetAllNews(paginationFilter);

            var getallnewsDto = _mapper.Map <IEnumerable <News>, IEnumerable <NewsDTO> >(getallnews);

            foreach (var item in getallnewsDto)
            {
                var source = await _sourceService.GetSourceById(item.SourceId);

                item.SourceName = source.SourceName;
            }

            if (pagination == null || pagination.PageNumber < 1 || pagination.PageSize < 1)
            {
                return(Ok(new PagedResponse <NewsDTO>(getallnewsDto)));
            }

            var paginationResponse = PaginationHelpers.CreatePaginationResponse(_uriService, paginationFilter, getallnewsDto);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 21
0
        public async Task <IEnumerable <OrderModel> > GetOrdersAsync(PaginationQuery paginationFilter, OrderFilter filter)
        {
            int skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize;

            if (filter is null)
            {
                var orderNoFilter =
                    _mapper.Map <IEnumerable <Order>, IEnumerable <OrderModel> >(
                        await _orderRepository.GetOrdersAsync(skip, paginationFilter.PageSize));

                return(orderNoFilter);
            }

            var orderFilter =
                _mapper.Map <IEnumerable <Order>, IEnumerable <OrderModel> >(
                    await _orderRepository.GetOrdersAsync(skip, paginationFilter.PageSize, filter));

            return(orderFilter);
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> GetAllCategories(
            [FromQuery] CategoryFilterQuery filterQuery,
            [FromQuery] PaginationQuery paginationQuery)
        {
            var pagination = _mapper.Map <PaginationParams>(paginationQuery);
            var filter     = _mapper.Map <CategoryFilterParams>(filterQuery);

            var categories = await _categoryService.GetAllCategoriesAsync(filter, pagination);

            if (pagination == null || pagination.IsValidPagination())
            {
                return(Ok(new PagedResponse <CategoryDto>(categories)));
            }

            var paginationResponse =
                PaginationHelpers.CreatePaginatedResponse(_uriGeneratorService, pagination, categories);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 23
0
        public PagedResponse <Game> GetAllGames(PaginationQuery paginationQuery)
        {
            IMongoCollection <Game> _games = _gamesRepository.GetGamesCollection();
            SortDefinition <Game>   sort   = Builders <Game> .Sort.Ascending("Name");

            FilterDefinition <Game> filter = Builders <Game> .Filter.Where(game => game.IsActive == true);

            var take = paginationQuery.PageSize > 100 ? 100 : paginationQuery.PageSize;
            var skip = (paginationQuery.PageNumber - 1) * take;

            if (take < 0 || skip < 0)
            {
                throw new InvalidGamesQueryParamsException("Query parameters PageSize and PageNumber should be a positive integer");
            }
            List <Game> games         = _games.Find(filter).Sort(sort).Skip(skip).Limit(take).ToList();
            int         numberOfGames = GetNumberOfActiveGames();

            return(new PagedResponse <Game>(games, paginationQuery, numberOfGames));
        }
        public async Task <IActionResult> GetAllOrders([FromQuery] PaginationQuery paginationQuery, [FromQuery] OrdersSortType sortType)
        {
            var username  = _userManager.GetUserId(HttpContext.User);
            var userId    = (await _userManager.FindByNameAsync(username)).Id;
            var orders    = _orderRepository.GetUserOrders(userId);
            var countTask = _orderRepository.GetUserOrders(userId).CountAsync();

            if (sortType == OrdersSortType.DatePlacedAsc)
            {
                orders = orders.OrderBy(o => o.OrderPlaced);
            }
            else if (sortType == OrdersSortType.DatePlacedDesc)
            {
                orders = orders.OrderByDescending(o => o.OrderPlaced);
            }
            else if (sortType == OrdersSortType.SubtotalAsc)
            {
                orders = orders.OrderBy(o => o.OrderTotal);
            }
            else if (sortType == OrdersSortType.SubtotalDesc)
            {
                orders = orders.OrderByDescending(o => o.OrderTotal);
            }
            if (paginationQuery != null)
            {
                orders = orders.Skip(paginationQuery.PageSize * (paginationQuery.PageNumber - 1)).Take(paginationQuery.PageSize);
            }

            if (paginationQuery == null || paginationQuery.PageNumber < 1 || paginationQuery.PageSize < 1)
            {
                paginationQuery = new PaginationQuery
                {
                    PageNumber = 0,
                    PageSize   = 0,
                };
            }
            var orderListTask = orders.ToArrayAsync();

            var paginationResponse = PaginationHelpers.CreatePaginatedResponse(_uriService, new PaginationFilter(paginationQuery), await orderListTask, await countTask);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 25
0
        public static PagedResponse <T> CreatePagedResponse(IUriService uriService, PaginationQuery pagination,
                                                            List <T> response, string controllerName)
        {
            var nextPage = pagination.PageNumber >= 1
                ? GetPageUri(uriService, pagination, pagination.PageNumber + 1, controllerName)
                : null;

            var previousPage = pagination.PageNumber - 1 >= 1
                ? GetPageUri(uriService, pagination, pagination.PageNumber - 1, controllerName)
                : null;

            return(new PagedResponse <T>
            {
                Data = response.Count <= pagination.PageSize? response : response.SkipLast(1),
                PageNumber = pagination.PageNumber,
                PageSize = pagination.PageSize,
                NextPage = response.Count > pagination.PageSize ? nextPage : null,
                PreviousPage = previousPage
            });
        }
Ejemplo n.º 26
0
        public async Task GetAllAsync_ShouldReturnPagedListOfAllProductsDto_WhenParametersAreNull()
        {
            // Arrange
            var products = _fixture.Build <Product>()
                           .CreateMany();

            var paginationQuery = new PaginationQuery();
            var page            = new PagedList <Product>(products.ToList(), products.ToList().Count(), 1, 10);

            _productRepository.GetAllAsync(null, null, paginationQuery).Returns(page);


            // Act
            var dto = await _sut.GetAllAsync(null, null, paginationQuery);

            // Assert
            dto.ShouldNotBeNull();
            dto.ShouldBeOfType(typeof(PageResultDto <ProductDto>));
            dto.Items.Count.ShouldBe(products.ToList().Count);
        }
Ejemplo n.º 27
0
        public async Task <ActionResult <ICollection <Client> > > GetAsync(
            [FromQuery] ClientsFiltrationQuery query,
            [FromQuery] PaginationQuery paginationQuery
            )
        {
            var pagination = _mapper.Map <PaginationFilter>(paginationQuery);
            var filter     = _mapper.Map <ClientsFilter>(query);

            var result = await _clientService.GetAllClients(filter, pagination);

            ICollection <ReadClientDto> readClients = new List <ReadClientDto>();
            ReadClientDto dto;

            foreach (Client client in result)
            {
                dto = _mapper.Map <ReadClientDto>(client);
                readClients.Add(dto);
            }
            return(Ok(new PagedResponse <ReadClientDto>(readClients, paginationQuery)));
        }
Ejemplo n.º 28
0
        public async Task GetAllAsync_ShouldReturnPagedListOfAllExercisesDto_WhenParametersAreNull(int count)
        {
            // Arrange
            var exercises = _fixture.Build <Exercise>()
                            .CreateMany(count: count);

            var paginationQuery = new PaginationQuery();
            var page            = new PagedList <Exercise>(exercises.ToList(), exercises.ToList().Count(), 1, 10);

            _exerciseRepository.GetAllAsync(Arg.Any <string>(), Arg.Any <string>(), paginationQuery).Returns(page);


            // Act
            var dto = await _sut.GetAllAsync(null, null, paginationQuery);

            // Assert
            dto.ShouldNotBeNull();
            dto.ShouldBeOfType(typeof(PageResultDto <ExerciseDto>));
            dto.Items.Count.ShouldBe(exercises.ToList().Count);
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> GetAll([FromQuery] GetAllPostQuery query, [FromQuery] PaginationQuery paginationQuery)
        {
            var pagination = _mapper.Map <PaginationFilter>(paginationQuery);
            var filter     = _mapper.Map <GetAllPostFilter>(query);
            var posts      = await _postService.GetPostsAsync(filter, pagination);

            /* Commented due AutoMapper use
             * var postResponse = posts.Select(p => new PostResponse
             * {
             *  Id = p.Id,
             *  Name = p.Name,
             *  UserId = p.UserId,
             *  Tags = p.Tags.Select(t => new TagResponse {Name = t.TagName})
             * }).ToList();*/

            var postResponse       = _mapper.Map <List <PostResponse> >(posts);
            var paginationResponse = PaginationHelper.CreatePaginatedResponse(_uriService, pagination, postResponse);

            return(Ok(paginationResponse));
        }
Ejemplo n.º 30
0
        public IQueryable <TEntity> GetAllQuery(PaginationQuery paginationQuery, Expression <Func <TEntity, bool> > filter)
        {
            var query = DbSet.AsQueryable();

            if (filter != null)
            {
                query = query.Where(filter);
            }

            if (paginationQuery.HasFilter && paginationQuery.HasFilterBy)
            {
                query = query.Where(paginationQuery);
            }

            query = query
                    .Skip(paginationQuery.Skip)
                    .Take(paginationQuery.Limit);

            return(query);
        }