Exemplo n.º 1
0
        public static IEnumerable<Season> GetAll(this SeasonService service, FetchSeasons request)
        {
            var seasons = new List<Season>();
            SeasonsResponse response;
            request.Page = 1;

            do
            {
                response = service.Get(request);
                seasons.AddRange(response.Seasons);

                request.Page++;
            } while (request.Page <= response.Paging.TotalCount);

            return seasons;
        }
Exemplo n.º 2
0
        public SeasonsResponse Get(FetchSeasons request)
        {
            int page = request.Page ?? 1;

            // Expression visitor to build query dynamically
            var visitor = Db.From<Season>();

            if (request.OnlyInProgress)
                visitor.Where(s => s.Start <= DateTime.UtcNow && s.End >= DateTime.UtcNow);

            if (request.NotFinal)
                visitor.Where(s => !s.Finalized);

            visitor.OrderByDescending(s => s.Start);

            var count = Db.Count(visitor);

            return new SeasonsResponse
            {
                Seasons = Db.Select(visitor.PageTo(page)),
                Paging = new Paging(Request != null ? Request.AbsoluteUri : string.Empty) { Page = page, TotalCount = count }
            };
        }