public IActionResult Index(SortState sortState = SortState.CustomersNameAsc, int page = 1)
        {
            CustomersFilterViewModel filter = HttpContext.Session.Get <CustomersFilterViewModel>(filterKey);

            if (filter == null)
            {
                filter = new CustomersFilterViewModel {
                    CustomerName = string.Empty
                };
                HttpContext.Session.Set(filterKey, filter);
            }

            string modelKey = $"{typeof(Customer).Name}-{page}-{sortState}-{filter.CustomerName}-{filter.CustomerSurname} -{filter.CustomerPatronymic}-{filter.CustomerPhoneNum}-{filter.CustomerAddress}-{filter.CustomerPassportInfo}-{filter.CustomerBirthDate}";

            if (!cache.TryGetValue(modelKey, out CustomerViewModel model))
            {
                model = new CustomerViewModel();

                IQueryable <Customer> customers = GetSortedEntities(sortState, filter.CustomerName, filter.CustomerSurname, filter.CustomerPatronymic, filter.CustomerPhoneNum, filter.CustomerAddress, filter.CustomerPassportInfo, filter.CustomerBirthDate);

                int count    = customers.Count();
                int pageSize = 10;
                model.PageViewModel = new PageViewModel(page, count, pageSize);

                model.Entities                 = count == 0 ? new List <Customer>() : customers.Skip((model.PageViewModel.CurrentPage - 1) * pageSize).Take(pageSize).ToList();
                model.SortViewModel            = new SortViewModel(sortState);
                model.CustomersFilterViewModel = filter;

                cache.Set(modelKey, model);
            }

            return(View(model));
        }
        public IActionResult Index(CustomersFilterViewModel filterModel, int page)
        {
            CustomersFilterViewModel filter = HttpContext.Session.Get <CustomersFilterViewModel>(filterKey);

            if (filter != null)
            {
                filter.CustomerName = filterModel.CustomerName;

                filter.CustomerSurname    = filterModel.CustomerSurname;
                filter.CustomerPatronymic = filterModel.CustomerPatronymic;

                filter.CustomerPhoneNum     = filterModel.CustomerPhoneNum;
                filter.CustomerAddress      = filterModel.CustomerAddress;
                filter.CustomerBirthDate    = filterModel.CustomerBirthDate;
                filter.CustomerPassportInfo = filterModel.CustomerPassportInfo;
                filter.CustomerGender       = filterModel.CustomerGender;

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

            return(RedirectToAction("Index", new { page }));
        }