public async Task <ObjectResult> Search(DivisionBaseSearchParams baseSearchParams)
        {
            var divisions = await _divisionService.Search(baseSearchParams);

            var result = _mapper.Map <PageView <DivisionViewModelList> >(divisions);

            return(Ok(result));
        }
        public async Task <PageView <DivisionShort> > Search(DivisionBaseSearchParams baseSearchParams)
        {
            var query = _context.Divisions.AsQueryable();

            if (!string.IsNullOrEmpty(baseSearchParams.Word))
            {
                var word = baseSearchParams.Word.ToLower();
                query = query.Where(d => d.Address.City.ToLower().Contains(word) ||
                                    d.Address.RegionWithType.ToLower().Contains(word) ||
                                    d.Address.Settlement.ToLower().Contains(word) ||
                                    d.Name.ToLower().Contains(word));
            }

            if (baseSearchParams.DivisionType.HasValue)
            {
                query = query.Where(d => d.DivisionType == baseSearchParams.DivisionType);
            }

            if (!string.IsNullOrEmpty(baseSearchParams.FiasId))
            {
                query = query.Where(d => d.Address.CityFiasId == baseSearchParams.FiasId ||
                                    d.Address.FiasId == baseSearchParams.FiasId ||
                                    d.Address.RegionFiasId == baseSearchParams.FiasId ||
                                    d.Address.SettlementFiasId == baseSearchParams.FiasId);
            }

            if (baseSearchParams.AdminUserId.HasValue)
            {
                query = query.Where(d => d.Admins.Any(u => u.Id == baseSearchParams.AdminUserId));
            }

            if (baseSearchParams.DirectorUserId.HasValue)
            {
                query = query.Where(d => d.Admins.Any(u => u.Id == baseSearchParams.DirectorUserId));
            }

            if (baseSearchParams.ParentDivisionId.HasValue)
            {
                query = query.Where(d => d.ParentDivisionId == baseSearchParams.ParentDivisionId.Value);
            }

            int skipCount = (baseSearchParams.Page - 1) * HARDCODED_SETTINGS.ITEMS_PER_PAGE;

            query = query.OrderBy(d => d.Name)
                    .Skip(skipCount)
                    .Take(baseSearchParams.Take);

            var pageView = new PageView <DivisionShort>
            {
                Items = await query.Select(d => new DivisionShort()
                {
                    Id               = d.Id,
                    Address          = d.Address.ToString(),
                    Name             = d.Name,
                    DirectorUserId   = d.DirectorUserId,
                    DirectorName     = d.Director.Name,
                    DivisionType     = d.DivisionType,
                    ParentDivisionId = d.ParentDivisionId
                }).ToListAsync(),
                CurrentPage = baseSearchParams.Page
            };

            return(pageView);
        }