Exemplo n.º 1
0
        public async Task <PagedResponse <SantaOrderPreview> > GetAllOrders(string santaId, SantaOrderStatusFilter filter, int count, int page)
        {
            var allSantaOrders = _db.Orders
                                 .Where(o => o.SantaId == santaId);

            switch (filter)
            {
            case SantaOrderStatusFilter.Approved:
                allSantaOrders = allSantaOrders.Where(o => o.Status == OrderStatus.Approved);
                break;

            case SantaOrderStatusFilter.Completed:
                allSantaOrders = allSantaOrders.Where(o => o.Status == OrderStatus.Completed);
                break;
            }

            var orders = await allSantaOrders
                         .OrderByDescending(o => o.Datetime)
                         .Skip(page * count)
                         .Take(count)
                         .Select(o => new SantaOrderPreview
            {
                Id         = o.Id,
                ClientName = o.Client.Name,
                Address    = o.Address,
                Datetime   = o.Datetime,
                Status     = o.Status
            })
                         .ToListAsync();

            return(new PagedResponse <SantaOrderPreview>
            {
                Items = orders,
                TotalCount = await allSantaOrders.CountAsync()
            });
        }
Exemplo n.º 2
0
 public async Task <PagedResponse <SantaOrderPreview> > GetAll(SantaOrderStatusFilter filter, int count, int page = 0)
 {
     return(await _santaOrdersService.GetAllOrders(User.Identity.GetUserId(), filter, count, page));
 }