public IActionResult Filter(CustomerIndexModel model, int page = 1)
 {
     var filters = model.Filters;
     if (filters == null)
     {
         return RedirectToAction("Index", new { page });
     }
     
     return RedirectToAction("Index", new
     {
         page,
         filter = JsonConvert.SerializeObject(filters, new JsonSerializerSettings
         {
             NullValueHandling = NullValueHandling.Ignore
         })
     });
 }
        public IActionResult Index(string filter, int page = 1)
        {

            var filtedObj = new CustomerIndexFilterModel();
            if (!string.IsNullOrEmpty(filter))
            {
                filtedObj = JsonConvert.DeserializeObject<CustomerIndexFilterModel>(filter);
            }

            if (User.IsInRole(RoleNames.Employee))
            {
                filtedObj.CityId = CurrentUser?.City?.Id;
            }

            var typesHousings = _context.TypesHousing.ToList();

            var filterData = new CustomersExtension.FilterParams
            {
                CityId = filtedObj.CityId,
                PriceTo = filtedObj.MinCost,
                PriceFrom = filtedObj.MaxCost,
                Page = page,
                //IsArchived = filtedObj.IsArchive,
                IsSiteAccessOnly = filtedObj.IsSiteAccessOnly
            };

            if (filtedObj.DistrictId.HasValue)
            {
                filterData.DistrictIds = new int[] { filtedObj.DistrictId.Value };
            }

            if (filtedObj.HousingTypeId.HasValue)
            {
                filterData.HouseTypeIds = new int[] { filtedObj.HousingTypeId.Value };
            }

            var applicationDbContext = _context.Clients
                .Include(c => c.City)
                .Include(c => c.CustomerAccount)
                .Include(c => c.Smses)
                .Include(c => c.User)
                .Include(c => c.TypesHousingToCustomers)
                .Include(x=> x.DistrictToClients)
                .Include(x => x.Phones);

            var query = applicationDbContext.Where(x => CustomersExtension.Filter(filterData)(x));

            int totalPages;
            int totalRows;
            var dbItems = query.PagedResult(page, 20, x => x.User, false, out totalRows, out totalPages).ToList();
            
            ViewBag.TotalItems = _context.Clients.Count();
            ViewBag.FilteredItemsCount = totalRows;

            var model = new CustomerIndexModel
            {
                Items = dbItems.Select(x => CustomerEditModel.Create(x)).ToList(),
                Filters = filtedObj,
                TotalPages = totalPages,
                CurrentPage = page
            };

            return View(model);
        }