Example #1
0
        public async Task <PagingResponse <VisitTypeDto> > GetVisitTypesAsync(VisitTypeParametersDto visitTypeParameters)
        {
            var queryStringParam = new Dictionary <string, string>
            {
                ["pageNumber"] = visitTypeParameters.PageNumber.ToString(),
                ["pageSize"]   = visitTypeParameters.PageSize.ToString(),
                ["sortOrder"]  = visitTypeParameters.SortOrder.ToString(),
                ["filters"]    = visitTypeParameters.Filters.ToString()
            };

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync(QueryHelpers.AddQueryString(uriVisitType.ToString(), queryStringParam)))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        var pagingResponse = new PagingResponse <VisitTypeDto>
                        {
                            Items    = JsonConvert.DeserializeObject <PageListVisitType>(content).VisitTypes,
                            Metadata = JsonConvert.DeserializeObject <MetaData>(response.Headers.GetValues("x-pagination").First())
                        };

                        pagingResponse.Filters   = visitTypeParameters.Filters;
                        pagingResponse.SortOrder = visitTypeParameters.SortOrder;
                        return(pagingResponse);
                    }
                    return(null);
                }
            }
        }
        public async Task <IActionResult> GetVisitTypes([FromQuery] VisitTypeParametersDto visitTypeParametersDto)
        {
            var visitTypessFromRepo = await _visitTypeRepository.GetVisitTypesAsync(visitTypeParametersDto);

            var paginationMetadata = new
            {
                totalCount        = visitTypessFromRepo.MetaData.TotalCount,
                pageSize          = visitTypessFromRepo.MetaData.PageSize,
                currentPageSize   = visitTypessFromRepo.MetaData.CurrentPageSize,
                currentStartIndex = visitTypessFromRepo.MetaData.CurrentStartIndex,
                currentEndIndex   = visitTypessFromRepo.MetaData.CurrentEndIndex,
                pageNumber        = visitTypessFromRepo.MetaData.PageNumber,
                totalPages        = visitTypessFromRepo.MetaData.TotalPages,
                hasPrevious       = visitTypessFromRepo.MetaData.HasPrevious,
                hasNext           = visitTypessFromRepo.MetaData.HasNext
            };

            Response.Headers.Add("X-Pagination",
                                 JsonSerializer.Serialize(paginationMetadata));

            var visitTypessDto = _mapper.Map <IEnumerable <VisitTypeDto> >(visitTypessFromRepo);
            var response       = new Response <IEnumerable <VisitTypeDto> >(visitTypessDto);

            return(Ok(response));
        }
Example #3
0
        public async Task <IActionResult> Index(int page = 1, int pageSize = 10, String filters = "", String sortOrder = "")
        {
            ViewBag.pageSize = pageSize;
            ViewBag.filter   = filters;

            ViewData["IdSortParm"]   = sortOrder == "Id" ? "-Id" : "Id";
            ViewData["NameSortParm"] = sortOrder == "Name" ? "-Name" : "Name";

            VisitTypeParametersDto visitTypeParameters = new VisitTypeParametersDto()
            {
                PageNumber = page,
                PageSize   = pageSize,
                SortOrder  = sortOrder,
                Filters    = filters
            };

            var pagingResponse = await _visitTypeRepo.GetVisitTypesAsync(visitTypeParameters);

            return(View(pagingResponse));
        }
        public async Task <PagedList <VisitType> > GetVisitTypesAsync(VisitTypeParametersDto visitTypeParameters)
        {
            if (visitTypeParameters == null)
            {
                throw new ArgumentNullException(nameof(visitTypeParameters));
            }

            var collection = _context.VisitTypes
                             as IQueryable <VisitType>; // TODO: AsNoTracking() should increase performance, but will break the sort tests. need to investigate

            var sieveModel = new SieveModel
            {
                Sorts   = visitTypeParameters.SortOrder ?? "Id",
                Filters = visitTypeParameters.Filters
            };

            collection = _sieveProcessor.Apply(sieveModel, collection);

            return(await PagedList <VisitType> .CreateAsync(collection,
                                                            visitTypeParameters.PageNumber,
                                                            visitTypeParameters.PageSize));
        }