public async Task <GalleryRoot> GetGallery([FromQuery] GalleryViewRoot galleryRoot)
 {
     if (AdditionalData.LastPhotoUpdate < DateTime.Now.AddMinutes(-5) &&
         galleryRoot.LastPhotoId == 0)
     {
         AdditionalData.LastPhotoUpdate = DateTime.Now;
         await _flickrService.RefreshPhotos();
     }
     return(await _galleryService.GetPhotos(galleryRoot));
 }
        public async Task <GalleryRoot> GetPhotos(GalleryViewRoot requestBody)
        {
            var photos = await GetPhotosFromCache();

            if (!string.IsNullOrEmpty(requestBody.Emotion))
            {
                photos = photos.FindAll(el => el.FacesFound.Any(face =>
                                                                face != null && string.Equals(face.CastEmotion, requestBody.Emotion
                                                                                              )));
            }
            var index = 0;

            if (requestBody.LastPhotoId != 0)
            {
                index = photos.IndexOf(photos.Find(el => el.Id == requestBody.LastPhotoId)) + 1;
            }
            var returnBody = _mapper.Map <GalleryRoot>(requestBody);

            returnBody.Photos      = photos.Skip(index).Take(requestBody.Count).ToList();
            returnBody.LastPhotoId = returnBody.Photos.Count > 0 ? returnBody.Photos.Last().Id : 0;
            return(returnBody);
        }