Example #1
0
 internal IEnumerable <MovieResponse> GetAllMovies()
 {
     using (var ctx = new TvApiContext())
     {
         return(ctx.Movies.Select(movie => new MovieResponse()
         {
             Id = movie.Id,
             Title = movie.Title,
             Year = movie.Year
         }).ToList());
     }
 }
Example #2
0
 internal void Add(MovieRequest movie)
 {
     using (var ctx = new TvApiContext())
     {
         ctx.Movies.Add(new Movie()
         {
             Title = movie.Title,
             Year  = movie.Year
         });
         ctx.SaveChanges();
     }
 }
Example #3
0
 internal IEnumerable <ReviewResponse> GetReviewsForMovie(int movieId)
 {
     using (var ctx = new TvApiContext())
     {
         var movie = ctx.Movies.Find(movieId);
         return(movie.Reviews.Select(x => new ReviewResponse()
         {
             Id = x.Id,
             Comment = x.Comment,
             Rate = x.Rate
         }).ToList());
     }
 }
Example #4
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();
            }
        }
Example #5
0
        internal MovieResponse Find(int id)
        {
            using (var ctx = new TvApiContext())
            {
                var movie = ctx.Movies.Find(id);
                if (movie == null)
                {
                    return(null);
                }

                return(new MovieResponse()
                {
                    Id = movie.Id,
                    Title = movie.Title,
                    Year = movie.Year
                });
            }
        }
Example #6
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();
            }
        }