Example #1
0
        public static IQueryable <T> Paginate <T>(this IQueryable <T> source, PaginationInfoDto pageInfo)
        {
            var total = source.Count();

            pageInfo.Total = total;
            var take = pageInfo.PageSize;
            var skip = (pageInfo.PageNumber - 1) * pageInfo.PageSize;

            if (take > total)
            {
                take = total;
                skip = 0;
            }

            if (skip > total)
            {
                skip = total;
                take = 0;
            }

            if (skip + take > total)
            {
                take = total - skip;
            }

            return(source.Skip(skip).Take(take));
        }
Example #2
0
        public async Task <PaginationResultDto <GatewayDto> > List(PaginationInfoDto pageInfo,
                                                                   string filterBy, string filterTerm, string sortBy, string sortDirection)
        {
            var gateways = _repository.GetAll();

            if (!String.IsNullOrEmpty(filterBy) && !String.IsNullOrEmpty(filterTerm))
            {
                gateways = gateways.FilterBy(filterBy, filterTerm);
            }

            if (!String.IsNullOrEmpty(sortBy))
            {
                gateways = gateways.SortBy(sortBy, sortDirection);
            }
            else
            {
                gateways = gateways.SortBy("Id", "asc");
            }

            var pageData = gateways.Count() > 0 ?  await gateways.Paginate(pageInfo).ToListAsync():new List <Domain.Gateway>();

            var pageDataDto = pageData.Select(gw => _mapper.Map <GatewayDto>(gw));

            return(new PaginationResultDto <GatewayDto>(pageInfo, pageDataDto));
        }
Example #3
0
        public HistoryDto GetHistory(HistoryRowSearchCriteriaDto searchCriteria, PaginationInfoDto paginationInfo)
        {
            IQueryable <HistoryRow> query = _dbContext.History;

            if (searchCriteria?.FromCurrency != null)
            {
                query = query.Where(e => EF.Functions.Like(e.FromCurrency, searchCriteria.FromCurrency));
            }
            if (searchCriteria?.ToCurrency != null)
            {
                query = query.Where(e => EF.Functions.Like(e.FromCurrency, searchCriteria.ToCurrency));
            }

            var totalCount = query.Count();

            if (paginationInfo != null)
            {
                var offset = paginationInfo.FromRecord;
                var count  = paginationInfo.ToRecord - offset;
                if (offset >= 0 && count > 0)
                {
                    query = query.Skip(offset).Take(count);
                }
            }

            var historyRows = query.AsEnumerable()
                              .Select(row => new HistoryRowDto(row.FromAmount, row.FromCurrency, row.ToCurrency, row.ToAmount, row.Date));

            return(new HistoryDto {
                HistoryRows = historyRows, RowsCount = totalCount
            });
        }
Example #4
0
        public async Task <ActionResult <PaginationResultDto <GatewayDto> > > GetGateways(
            [FromQuery] int pageNumber    = 1,
            [FromQuery] int pageSize      = 10,
            [FromQuery] string filterBy   = "",
            [FromQuery] string searchTerm = "",
            [FromQuery] string sortBy     = "")
        {
            var    pageInfo = new PaginationInfoDto(pageNumber, pageSize);
            string sortProperty;
            string sortDirection;

            switch (sortBy)
            {
            case "name":
            case "name_asc":
                sortProperty  = nameof(GatewayDto.Name);
                sortDirection = "asc";
                break;

            case "name_desc":
                sortProperty  = nameof(GatewayDto.Name);
                sortDirection = "desc";
                break;

            case "serialNumber":
            case "serialNumber_asc":
                sortProperty  = nameof(GatewayDto.SerialNumber);
                sortDirection = "asc";
                break;

            case "serialNumber_desc":
                sortProperty  = nameof(GatewayDto.SerialNumber);
                sortDirection = "desc";
                break;

            case "iPV4Address":
            case "iPV4Address_asc":
                sortProperty  = nameof(GatewayDto.IPV4Address);
                sortDirection = "asc";
                break;

            case "iPV4Address_desc":
                sortProperty  = nameof(GatewayDto.IPV4Address);
                sortDirection = "desc";
                break;

            default:
                sortProperty  = nameof(GatewayDto.Id);
                sortDirection = "asc";
                break;
            }

            return(await _gatewayService.List(pageInfo, filterBy, searchTerm, sortProperty, sortDirection));
        }
Example #5
0
        protected async Task <PagedResultDto <StudentDto> > GetDtos(PaginationInfoDto paginationInfo, IQueryable <Student> query)
        {
            var result = query.PageResult(paginationInfo.PageNumber, paginationInfo.PageSize);

            if (result.CurrentPage > result.PageCount && result.PageCount > 0)
            {
                result = query.PageResult(result.PageCount, paginationInfo.PageSize);
            }

            return(new PagedResultDto <StudentDto>
            {
                Items = (await result.Queryable.ToArrayAsync()).Select(x => _mapper.Adapt <StudentDto>(x)).ToList(),
                TotalRows = result.RowCount,
                TotalPages = result.PageCount,
                CurrentPage = result.CurrentPage,
                ItemsPerPage = result.PageSize
            });
        }
Example #6
0
        public async Task <PagedResultDto <StudentDto> > GetStudents(
            PaginationInfoDto paginationInfo,
            string identifier = "",
            string firstName  = "",
            string lastName   = "",
            string middleName = "",
            int?gender        = null)
        {
            IQueryable <Student> rs = _applicationContext.Students.Where(r => !r.IsDeleted);

            if (!String.IsNullOrEmpty(identifier))
            {
                rs = rs.Where(r => r.Identifier.Contains(identifier));
            }

            if (!String.IsNullOrEmpty(firstName))
            {
                rs = rs.Where(r => r.FirstName.Contains(firstName));
            }

            if (!String.IsNullOrEmpty(lastName))
            {
                rs = rs.Where(r => r.LastName.Contains(identifier));
            }

            if (!String.IsNullOrEmpty(middleName))
            {
                rs = rs.Where(r => r.MiddleName.Contains(middleName));
            }

            if (gender.HasValue)
            {
                rs = rs.Where(r => r.Gender.Equals(gender.Value));
            }


            return(await GetDtos(paginationInfo, rs.OrderBy(x => x.Id)));
        }
Example #7
0
 public HistoryDto History([FromQuery] HistoryRowSearchCriteriaDto searchCriteriaDto, [FromQuery] PaginationInfoDto paginationInfoDto)
 {
     return(_historyService.GetHistory(searchCriteriaDto, paginationInfoDto));
 }