public async Task <MoviePostDTO> PostMovie(MoviePostDTO moviePostDTO) { if (moviePostDTO == null) { throw new ArgumentNullException(nameof(moviePostDTO)); } var movie = _context.Movies.Add(new Movie() { Name = moviePostDTO.Name, Director = moviePostDTO.Director, Aired = moviePostDTO.Aired, Duration = moviePostDTO.Duration, Image = moviePostDTO.Image, MovieGenres = null, MovieActors = null }); foreach (MovieActorDTO movieActorDTO in moviePostDTO.MovieActorDTOs) { Actor actor = _context.Actors.Find(movieActorDTO.ActorId); _context.MovieActors.Add(new MovieActor() { MovieId = movie.Entity.Id, Movie = movie.Entity, ActorId = actor.Id, Actor = actor }); } foreach (MovieGenreDTO movieGenreDTO in moviePostDTO.MovieGenreDTOs) { Genre genre = _context.Genres.Find(movieGenreDTO.GenreId); _context.MovieGenres.Add(new MovieGenre() { MovieId = movie.Entity.Id, Movie = movie.Entity, GenreId = genre.Id, Genre = genre }); } await _context.SaveChangesAsync().ConfigureAwait(false); moviePostDTO.Id = movie.Entity.Id; return(moviePostDTO); }
public async Task <GenrePostDTO> PostGenre(GenrePostDTO genrePostDTO) { if (genrePostDTO == null) { throw new ArgumentNullException(nameof(genrePostDTO)); } var genreResult = _context.Genres.Add(new Genre() { GenreName = genrePostDTO.GenreName }); await _context.SaveChangesAsync().ConfigureAwait(false); genrePostDTO.Id = genreResult.Entity.Id; return(genrePostDTO); }
public async Task <bool> SaveChangesAsync() { try { return(await _context.SaveChangesAsync() > 0); } catch (Exception ex) { throw ex; } }
public async Task <ActorPostDTO> PostActor(ActorPostDTO actorPostDTO) { if (actorPostDTO == null) { throw new ArgumentNullException(nameof(actorPostDTO)); } var actorResult = _context.Actors.Add(new Actor() { FullName = actorPostDTO.FullName, Birthday = actorPostDTO.Birthday, Image = actorPostDTO.Image }); await _context.SaveChangesAsync().ConfigureAwait(false); actorPostDTO.Id = actorResult.Entity.Id; return(actorPostDTO); }
public async Task <WatchListDTO> UpdateWatchlistItem(string id, WatchListDTO watchListDTO) { if (watchListDTO == null) { throw new ArgumentNullException(nameof(watchListDTO)); } try { WatchList watchlist = await _context.WatchLists .FirstOrDefaultAsync(w => w.UserId == id && w.MovieId == watchListDTO.MovieId).ConfigureAwait(false); watchlist.Status = getStatus(watchListDTO.Status); watchlist.Score = watchListDTO.Score; await _context.SaveChangesAsync().ConfigureAwait(false); } catch (DbUpdateConcurrencyException) { if (await UserExists(id).ConfigureAwait(false) == false) { return(null); } else { throw; } } return(new WatchListDTO() { UserId = id, MovieId = watchListDTO.MovieId, Status = watchListDTO.Status, Score = watchListDTO.Score }); }