Exemple #1
0
        public async Task <ICollection <BusinessDto> > FindBusinesses(BusinessSearchParams businessSearchParams)
        {
            var businesses = _context.Business
                             .Where(b => b.IsOperational == true)
                             .Include(b => b.BusinessType)
                             .Include(b => b.City)
                             .ThenInclude(c => c.State)
                             .ThenInclude(s => s.Country)
                             .OrderBy(b => b.BusinessName)
                             .AsQueryable();

            if (!String.IsNullOrEmpty(businessSearchParams.Search) && !String.IsNullOrWhiteSpace(businessSearchParams.Search))
            {
                businesses = businesses.Where(btf =>
                                              EF.Functions.Like(btf.BusinessName.ToString(), $"%{businessSearchParams.Search}%") ||
                                              EF.Functions.Like(btf.BusinessDescription.ToString(), $"%{businessSearchParams.Search}%") ||
                                              EF.Functions.Like(btf.BusinessEmail.ToString(), $"%{businessSearchParams.Search}%") ||
                                              EF.Functions.Like(btf.PrimaryPhoneNumber.ToString(), $"%{businessSearchParams.Search}%")
                                              );
            }
            if (!String.IsNullOrEmpty(businessSearchParams.City) && !String.IsNullOrWhiteSpace(businessSearchParams.City))
            {
                businesses = businesses.Where(b =>
                                              EF.Functions.Like(b.City.CityNormalizedName.ToString(), $"%{businessSearchParams.City}%")
                                              );
            }
            if (!String.IsNullOrEmpty(businessSearchParams.Type) && !String.IsNullOrWhiteSpace(businessSearchParams.Type))
            {
                businesses = businesses.Where(b =>
                                              EF.Functions.Like(b.BusinessType.BusinessTypeNormalizedName.ToString(), $"%{businessSearchParams.Type}%")
                                              );
            }
            var businessesToReturn = await businesses.ToListAsync();

            return(_mapper.Map <ICollection <BusinessDto> >(businessesToReturn));
        }
        public async Task <IActionResult> GetAllBusinesses([FromQuery] BusinessSearchParams businessSearchParams)
        {
            var businesses = await _businessService.FindBusinesses(businessSearchParams);

            return(Ok(businesses));
        }
Exemple #3
0
        public async Task <ICollection <BusinessDto> > FindBusinesses(BusinessSearchParams businessSearchParams)
        {
            var businesses = await _businessRepository.FindBusinesses(businessSearchParams);

            return(businesses);
        }