/// <summary> /// Adds images to given movie /// </summary> /// <param name="images">List of image upload results</param> /// <param name="movieId">Movie id</param> public async Task AddMovieImages(IEnumerable <UploadedImage> images, Guid movieId) { var imagesToAdd = images.Select(i => new Image { Url = i.Filepath }).ToList(); for (int i = 0; i < imagesToAdd.Count; ++i) { await ImageRepo.CreateAsync(imagesToAdd[i]); await ImageRepo.SaveChangesAsync(); } var movieImages = new List <MovieImage>(imagesToAdd.Count()); foreach (var img in imagesToAdd) { var type = images.FirstOrDefault(i => i.Filepath == img.Url)?.ImageType; var movieImage = new MovieImage { MovieId = movieId, ImageType = type, ImageId = img.Id }; movieImages.Add(movieImage); } MovieImageRepo.AddRange(movieImages); await MovieImageRepo.SaveChangesAsync(); }
/// <summary> /// Adds image to given movie /// </summary> /// <param name="url">Image location</param> /// <param name="movieId">Movie id</param> /// <param name="type">Image type</param> public async Task AddMovieImage(string url, Guid movieId, MovieImageTypeEnum type) { var image = new Image { Url = url }; await ImageRepo.CreateAsync(image); await ImageRepo.SaveChangesAsync(); var movieImage = new MovieImage { ImageId = image.Id, MovieId = movieId, ImageType = MovieImageType.ToStr(type) }; await MovieImageRepo.CreateAsync(movieImage); await MovieImageRepo.SaveChangesAsync(); }