internal void Add(MovieRequest movie) { using (var ctx = new TvApiContext()) { ctx.Movies.Add(new Movie() { Title = movie.Title, Year = movie.Year }); ctx.SaveChanges(); } }
internal void Delete(int id) { using (var ctx = new TvApiContext()) { var movie = ctx.Movies.Find(id); if (movie == null) { return; } ctx.Movies.Remove(movie); ctx.SaveChanges(); } }
internal void AddReviewToMovie(int movieId, ReviewRequest request) { using (var ctx = new TvApiContext()) { var movie = ctx.Movies.Find(movieId); if (movie == null) { throw new TvApiException($"Cannot add review. Invalid move id = {movieId}"); } movie.Reviews.Add(new Review() { Comment = request.Comment, Rate = request.Rate }); ctx.SaveChanges(); } }