Ejemplo n.º 1
0
        public async Task <IActionResult> GetVisitStates([FromQuery] VisitStateParametersDto visitStateParametersDto)
        {
            var visitStatesFromRepo = await _visitStateRepository.GetVisitStatesAsync(visitStateParametersDto);

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

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

            var stateVisitsDto = _mapper.Map <IEnumerable <VisitStateDto> >(visitStatesFromRepo);
            var response       = new Response <IEnumerable <VisitStateDto> >(stateVisitsDto);

            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task <PagingResponse <VisitStateDto> > GetVisitStatesAsync(VisitStateParametersDto visitStateParameters)
        {
            var queryStringParam = new Dictionary <string, string>
            {
                ["pageNumber"] = visitStateParameters.PageNumber.ToString(),
                ["pageSize"]   = visitStateParameters.PageSize.ToString(),
                ["sortOrder"]  = visitStateParameters.SortOrder.ToString(),
                ["filters"]    = visitStateParameters.Filters.ToString()
            };

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

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

                        pagingResponse.Filters   = visitStateParameters.Filters;
                        pagingResponse.SortOrder = visitStateParameters.SortOrder;
                        return(pagingResponse);
                    }
                    return(null);
                }
            }
        }
Ejemplo n.º 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";

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

            var pagingResponse = await _visitStateRepo.GetVisitStatesAsync(companyParameters);

            return(View(pagingResponse));
        }
Ejemplo n.º 4
0
        public async Task <PagedList <VisitState> > GetVisitStatesAsync(VisitStateParametersDto visitStateParametersDto)
        {
            if (visitStateParametersDto == null)
            {
                throw new ArgumentNullException(nameof(visitStateParametersDto));
            }

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

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

            collection = _sieveProcessor.Apply(sieveModel, collection);

            return(await PagedList <VisitState> .CreateAsync(collection,
                                                             visitStateParametersDto.PageNumber,
                                                             visitStateParametersDto.PageSize));
        }