public IEnumerable <Photo> GetPhotos(int memberID, PhotosResourceParameters photosResourceParameters)
        {
            if (photosResourceParameters == null)
            {
                throw new ArgumentNullException(nameof(photosResourceParameters));
            }
            // Dealing with IQueryable allows us to pile where clause sections without loading the data.
            // Pulling the data and filtering it is insanely nonperformant
            var collection = _context.Photos as IQueryable <Photo>;

            if (photosResourceParameters.ViewCount > 0)
            {
                collection = collection.Where(c => c.MemberID == memberID && c.Views >= photosResourceParameters.ViewCount);
            }

            if (!string.IsNullOrWhiteSpace(photosResourceParameters.SearchQuery))
            {
                var searchQuery = photosResourceParameters.SearchQuery.Trim();

                collection = collection.Where(w => w.Description.Contains(searchQuery));
            }

            return(collection.ToList());
        }
Ejemplo n.º 2
0
        public ActionResult <IEnumerable <PhotoDto> > GetPhotosForMember(int memberID, [FromQuery] PhotosResourceParameters photosResourceParameters)
        {
            if (!_photoLibraryRepository.MemberExists(memberID))
            {
                return(NotFound());
            }

            var photosFromRepo = _photoLibraryRepository.GetPhotos(memberID, photosResourceParameters);

            return(Ok(_mapper.Map <IEnumerable <PhotoDto> >(photosFromRepo)));
        }