public IActionResult Index(PaymentsFilterViewModel filterModel, int page)
        {
            PaymentsFilterViewModel filter = HttpContext.Session.Get <PaymentsFilterViewModel>(filterKey);

            if (filter != null)
            {
                filter.Name = filterModel.Name;
                filter.Date = filterModel.Date;
                filter.Sum  = filterModel.Sum;

                HttpContext.Session.Remove(filterKey);
                HttpContext.Session.Set(filterKey, filter);
            }

            return(RedirectToAction("Index", new { page }));
        }
        // GET: Payments
        public async Task <IActionResult> Index(SortState sortState = SortState.PaymentsNameOfCoursesAsc, int page = 1)
        {
            PaymentsFilterViewModel filter = HttpContext.Session.Get <PaymentsFilterViewModel>(filterKey);

            if (filter == null)
            {
                filter = new PaymentsFilterViewModel
                {
                    Name = string.Empty,
                    Date = null,
                    Sum  = null
                };
                HttpContext.Session.Set(filterKey, filter);
            }

            string key = $"{typeof(Payment).Name}-{page}-{sortState}-{filter.Name}-{filter.Date}-{filter.Sum}";

            if (!_cache.TryGetValue(key, out PaymentViewModel model))
            {
                model = new PaymentViewModel();

                IQueryable <Payment> payments = GetSortedPayments(sortState, filter.Name, filter.Date, filter.Sum);

                int count = payments.Count();

                model.PageViewModel = new PageViewModel(page, count, pageSize);

                model.Payments = count == 0
                    ? new List <Payment>()
                    : payments.Skip((model.PageViewModel.PageIndex - 1) * pageSize).Take(pageSize).ToList();
                model.SortViewModel           = new SortViewModel(sortState);
                model.PaymentsFilterViewModel = filter;

                _cache.Set(key, model);
            }
            return(View(model));
        }