Пример #1
0
        public async Task <IActionResult> Index(int sectionId, [FromQuery] int current = 1, [FromQuery] int rowCount = 10, [FromQuery] string searchPhrase = null)
        {
            var section = await sectionRepo.GetSectionAsync(sectionId) ?? throw new ArgumentNullException("section");

            var query = repo.GetAllSlides(section);

            if (!string.IsNullOrEmpty(searchPhrase))
            {
                query = query.Where(x => x.Name.Contains(searchPhrase, StringComparison.OrdinalIgnoreCase) || x.Header.Contains(searchPhrase, StringComparison.OrdinalIgnoreCase));
            }
            var total = query.Count();

            var sections = query.Skip((current - 1) * rowCount).Take(rowCount);

            var model = new PagedModel <SlideViewModel>
            {
                current  = current,
                rowCount = rowCount,
                total    = total,
                rows     = from s in query
                           select CreateSlideViewModel(s)
            };


            //.Select(x =>
            //new SectionViewModel
            //{
            //    SectionId = x.SectionId,
            //    Name = x.Name,
            //});
            return(Negotiate(model));
        }