public IQueryable <Individual> GetAllFiltered(IndividualsFilterModel filter)
        {
            var query = _db.Individuals.Include(i => i.City).Include(i => i.Phones).AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter.QuickSearchFilter)) // Quick Filter
            {
                query = query.Where(i => i.Name.Contains(filter.QuickSearchFilter) ||
                                    i.Surname.Contains(filter.QuickSearchFilter) ||
                                    i.PersonalNumber.Contains(filter.QuickSearchFilter));
            }
            else // Detailed Filter
            {
                query = query
                        .Where(i => i.Name.Contains(filter.Name.EmptyIfNull()))
                        .Where(i => i.Surname.Contains(filter.Surname.EmptyIfNull()))
                        .Where(i => !filter.Gender.HasValue || (int)i.Gender == filter.Gender.Value)
                        .Where(i => i.PersonalNumber.Contains(filter.PersonalNumber.EmptyIfNull()))
                        .Where(i => !filter.BirthDate.HasValue || i.BirthDate.Date == filter.BirthDate.Value.Date);

                if (filter.City != null)
                {
                    query = query.Where(i => i.City != null && i.City.Name != null && i.City.Name.Contains(filter.City));
                }
            }

            return(query);
        }
        public async Task <IActionResult> Index(IndividualsFilterModel filter)
        {
            var query = _individualsManager.GetAllFiltered(filter);

            if (filter.PageNumber < 1)
            {
                filter.PageNumber = 1;
            }

            return(View(
                       new IndividualsListViewModel
            {
                Individuals = await query
                              .Skip(_recordsPerPage * (filter.PageNumber - 1))
                              .Take(_recordsPerPage)
                              .ToListAsync(),
                Page = new PageViewModel(await query.CountAsync(), filter.PageNumber, _recordsPerPage),
                Filters = filter
            }));
        }