예제 #1
0
 internal void Add(MovieRequest movie)
 {
     using (var ctx = new TvApiContext())
     {
         ctx.Movies.Add(new Movie()
         {
             Title = movie.Title,
             Year  = movie.Year
         });
         ctx.SaveChanges();
     }
 }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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();
            }
        }