public IEnumerable <Owner> GetOwners(OwnersResourceParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (string.IsNullOrWhiteSpace(parameters.Name) && string.IsNullOrWhiteSpace(parameters.Description))
            {
                GetOwners();
            }

            var collection = _context.Owners as IQueryable <Owner>;

            if (!string.IsNullOrWhiteSpace(parameters.Name))
            {
                var name = parameters.Name.ToLower().Trim();
                collection = collection.Where(o => o.Name.ToLower().Contains(name));
            }

            if (!string.IsNullOrWhiteSpace(parameters.Description))
            {
                var description = parameters.Description.ToLower().Trim();
                collection = collection.Where(o => o.Description.ToLower().Contains(description.ToLower()));
            }

            return(collection.Include(o => o.Dogs).OrderBy(o => o.Name).ToList());
        }
Ejemplo n.º 2
0
        public ActionResult <IEnumerable <OwnerDto> > GetOwners([FromQuery] OwnersResourceParameters parameters)
        {
            var ownersFromRepo = _ownerRepository.GetOwners(parameters);

            return(Ok(_mapper.Map <IEnumerable <OwnerDto> >(ownersFromRepo)));
        }