// GET: Attestation
        public async Task <IActionResult> Index(int?region, string dateFrom, string dateTo, int page = 1)
        {
            int pageSize = 5;   // количество элементов на странице

            IQueryable <Attestation> attestations = _context.Attestations.Include(s => s.Region).Include(s => s.Comission).Include(s => s.AttestationUserBelts).OrderByDescending(a => a.IssueDate);

            ViewBag.Regions = _regionsList;

            if (region != null && region != 0)
            {
                attestations    = attestations.Where(p => p.RegionId == region);
                ViewBag.Regions = _regionsHandler.GetSelectedListRegionsWithSelection((int)region);
            }
            if (!string.IsNullOrEmpty(dateFrom) || !string.IsNullOrEmpty(dateTo))
            {
                var _dateFrom = string.IsNullOrEmpty(dateFrom) ? DateTime.MinValue : DateTime.Parse(dateFrom);
                var _dateTo   = string.IsNullOrEmpty(dateTo) ? DateTime.MaxValue : DateTime.Parse(dateTo);
                attestations = attestations.Where(p => p.IssueDate >= _dateFrom && p.IssueDate <= _dateTo);
            }

            var count = await attestations.CountAsync();

            var items = await attestations.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            PageViewModel         pageViewModel = new PageViewModel(count, page, pageSize);
            AttestationsViewModel viewModel     = new AttestationsViewModel
            {
                PageViewModel = pageViewModel,
                Attestations  = items
            };

            return(View(viewModel));
        }
Exemple #2
0
        // GET: Comissions
        public async Task <IActionResult> Index(int?region, string title)
        {
            IQueryable <Comission> comissions = _context.Comissions.Include(s => s.Region)
                                                .Include(s => s.SportmanComissions).ThenInclude(a => a.Sportman);

            ViewBag.Regions = _regionsList;

            if (region != null && region != 0)
            {
                comissions      = comissions.Where(p => p.RegionId == region);
                ViewBag.Regions = _regionsHandler.GetSelectedListRegionsWithSelection((int)region);
            }
            if (!string.IsNullOrEmpty(title))
            {
                comissions = comissions.Where(p => p.Name.Contains(title));
            }

            return(View(await comissions.ToListAsync()));
        }