Beispiel #1
0
        public async Task <PagedList <Show> > GetAllShows(ShowParams showParams)
        {
            var shows = _context.Shows.AsQueryable();

            if (!string.IsNullOrEmpty(showParams.ShowName))
            {
                shows = shows.Where(s => s.Name.ToLower().Contains(showParams.ShowName.ToLower()));
            }
            if (!string.IsNullOrEmpty(showParams.StartPeriod.ToString()))
            {
                shows = shows.Where(s => s.StartPeriod >= showParams.StartPeriod);
            }
            if (!string.IsNullOrEmpty(showParams.EndPeriod.ToString()))
            {
                shows = shows.Where(s => s.EndPeriod <= showParams.EndPeriod);
            }
            if (!string.IsNullOrEmpty(showParams.StartDate.ToString()))
            {
                shows = shows
                        .Include(s => s.ShowTimes
                                 .Where(st => st.StartDate >= showParams.StartDate));
            }
            if (!string.IsNullOrEmpty(showParams.EndDate.ToString()))
            {
                shows = shows
                        .Include(s => s.ShowTimes
                                 .Where(st => st.EndDate <= showParams.EndDate));
            }
            return(await PagedList <Show> .CreateAsync(shows.OrderBy(s => s.StartPeriod),
                                                       showParams.PageNumber, showParams.PageSize));
        }
        public async Task <IActionResult> GetShows(ShowParams showParams)
        {
            var shows = await _service.GetAllShows(showParams);

            Response.AddPagination(shows.CurrentPage,
                                   shows.PageSize, shows.TotalCount,
                                   shows.TotalPages);
            return(Ok(shows));
        }