public IActionResult GetPagedData([FromQuery] PagesParams paginationQuery)
        {
            if (!IsPaginationValid(paginationQuery))
            {
                return(BadRequest("Bad pagination"));
            }

            var nextRangeStart = paginationQuery.PageNumber * paginationQuery.PageSize;
            var result         = paginationQuery.PageNumber < Data.Count ?
                                 Data.GetRange(nextRangeStart, Math.Min(paginationQuery.PageSize, Data.Count - nextRangeStart))
                : new List <DataDto>();

            //Pagination object result must include the items being returned, the initial query options and the max number of items if available
            return(new PaginationObjectResult(result, paginationQuery, Data.Count));
        }
Ejemplo n.º 2
0
        public IActionResult GetPagedData([FromQuery] PagesParams paginationQuery, [FromQuery] MyFilterParams filterQuery)
        {
            if (!IsPaginationValid(paginationQuery) || !IsFilterValid(filterQuery))
            {
                return(BadRequest("Bad pagination"));
            }

            var nextRangeStart = paginationQuery.PageNumber * paginationQuery.PageSize;
            var result         = paginationQuery.PageNumber < Data.Count ?
                                 Data.Where(x => x.Number >= filterQuery.MinimumNumber && x.Number <= filterQuery.MaximumNumber)
                                 .Skip(nextRangeStart)
                                 .Take(paginationQuery.PageSize)
                                 .ToList()
                : new List <DataDto>();

            //Pagination object result must include the items being returned, the initial query options and the max number of items if available
            return(new PaginationObjectResult(result, paginationQuery, Data.Count));
        }
Ejemplo n.º 3
0
        public async Task <PageDate <SaleView> > GetList(PagesParams paramers)
        {
            var sql = @"SELECT s.Id,
                        s.Datebuy as DateBuy,
                        s.Count,
                        s.Summ,
                        c.Name as ClientName,
                        sf.Name as SoftName,
                        sf.Price as PriceOne
                    FROM sales s
                    join clients c on c.Id = s.Id_client
                    join softs sf on sf.Id = s.Id_soft
                    order by s.Id
                    LIMIT  @getCount
                    OFFSET @skipCount;";

            var             skipCount = (paramers.PageNumber - 1) * paramers.PageSize;
            List <SaleView> sales     = new List <SaleView>();

            using (var bd = new SqliteConnection(_connectStr))
            {
                sales = (await bd.QueryAsync <SaleView>(sql,
                                                        new{
                    skipCount = skipCount,
                    getCount = paramers.PageSize
                })).AsList();
            }

            int count;

            sql = "select count(*) from sales";
            using (var bd = new SqliteConnection(_connectStr))
            {
                count = await bd.QueryFirstAsync <int>(sql);
            }

            return(new PageDate <SaleView>()
            {
                CurrentPage = paramers.PageNumber,
                Items = sales,
                PageSize = paramers.PageSize,
                CountPage = (int)Math.Ceiling(count / (double)paramers.PageSize)
            });
        }
Ejemplo n.º 4
0
        public async Task <PageDate <Soft> > GetList(PagesParams paramers)
        {
            var sql = @"SELECT Id,
                            Name,
                            Description,
                            Price,
                            Count
                        FROM softs
                        order by Id
                        LIMIT @getCount
                        OFFSET @skipCount;
                        ";

            var         skipCount = (paramers.PageNumber - 1) * paramers.PageSize;
            List <Soft> softs     = new List <Soft>();

            using (var bd = new SqliteConnection(_connectStr))
            {
                softs = (await bd.QueryAsync <Soft>(
                             sql, new {
                    skipCount = skipCount,
                    getCount = paramers.PageSize
                }
                             )).AsList();
            }

            int count;

            sql = @"select count(*) from softs";
            using (var bd = new SqliteConnection(_connectStr))
            {
                count = bd.QueryFirst <int>(sql);
            }

            return(new PageDate <Soft>()
            {
                CurrentPage = paramers.PageNumber,
                Items = softs,
                PageSize = paramers.PageSize,
                CountPage = (int)Math.Ceiling(count / (double)paramers.PageSize)
            });
        }
Ejemplo n.º 5
0
 public async Task <PageDate <Client> > GetClients([FromQuery] PagesParams pagesParams)
 {
     return(await _repo.GetList(pagesParams));
 }
Ejemplo n.º 6
0
        public async Task <PageDate <LogRow> > GetList(PagesParams paramers)
        {
            var sql = @"";

            if (paramers.Filter == "All")
            {
                sql = @"SELECT Id,
                        DateTime,
                        Level,
                        Message,
                        StackTrace
                    FROM Logs
                    order by Id desc
                    LIMIT @getCount
                    OFFSET @skipCount;";
            }
            else
            {
                sql = @"SELECT Id,
                        DateTime,
                        Level,
                        Message,
                        StackTrace
                    FROM Logs
                    where Level = @level
                    order by Id desc
                    LIMIT @getCount
                    OFFSET @skipCount;";
            }

            var           skipCount = (paramers.PageNumber - 1) * paramers.PageSize;
            List <LogRow> logs      = new List <LogRow>();

            using (var bd = new SqliteConnection(_connectStr))
            {
                logs = (await bd.QueryAsync <LogRow>(sql,
                                                     new {
                    skipCount = skipCount,
                    getCount = paramers.PageSize,
                    level = paramers.Filter
                }
                                                     )).AsList();
            }

            int count;

            if (paramers.Filter == "All")
            {
                sql = @"select count(*) from Logs";
            }
            else
            {
                sql = @"select count(*) from Logs where Level = @level";
            }


            using (var bd = new SqliteConnection(_connectStr))
            {
                count = await bd.QueryFirstAsync <int>(sql, new { level = paramers.Filter });
            }

            return(new PageDate <LogRow>()
            {
                CurrentPage = paramers.PageNumber,
                Items = logs,
                PageSize = paramers.PageSize,
                CountPage = (int)Math.Ceiling(count / (double)paramers.PageSize)
            });
        }
Ejemplo n.º 7
0
 public async Task <PageDate <SaleView> > GetSales([FromQuery] PagesParams pagesParams)
 {
     return(await _repo.GetList(pagesParams));
 }
Ejemplo n.º 8
0
 public async Task <PageDate <LogRow> > GetLog([FromQuery] PagesParams pagesParams)
 {
     return(await _repo.GetList(pagesParams));
 }
Ejemplo n.º 9
0
 public async Task <PageDate <Soft> > GetSoft([FromQuery] PagesParams pagesParams)
 {
     return(await _repo.GetList(pagesParams));
 }