Beispiel #1
0
        /// <summary>
        /// Removes movie image entity and image entity
        /// and if there are no other image entities
        /// that points to the deleted image entity
        /// method returns underlying image url
        /// otherwise null is returned
        /// </summary>
        /// <param name="movieImageId">MovieImage entity id</param>
        /// <returns>Underlying image url or null</returns>
        public async Task <string> RemoveMovieImage(Guid movieImageId)
        {
            var movieImage = await MovieImageRepo
                             .GetAll()
                             .FirstOrDefaultAsync(mi => mi.Id == movieImageId);

            if (movieImage == null)
            {
                return(null);
            }
            var image = await ImageRepo
                        .GetAll()
                        .FirstOrDefaultAsync(i => i.Id == movieImage.ImageId);

            var otherImagesWithSameUrl = await ImageRepo
                                         .GetAll(i => i.Url == image.Url && i.Id != image.Id)
                                         .ToListAsync();

            MovieImageRepo.Delete(movieImage);
            await MovieImageRepo.SaveChangesAsync();

            ImageRepo.Delete(image);
            await ImageRepo.SaveChangesAsync();

            return(otherImagesWithSameUrl.Count > 0 ? null : image.Url);
        }
        public void Scrape(int maxNotFoundStreak)
        {
            int notFoundStreak = 0;

            for (int id = 0; notFoundStreak < maxNotFoundStreak; id++)
            {
                try
                {
                    _imageRepo.AddOrUpdate(_fetchImage(id));
                    notFoundStreak = 0;
                }
                catch (NotFoundException)
                {
                    _imageRepo.Delete(id);
                    notFoundStreak++;
                }
            }
        }