public IActionResult Post([FromBody] UserRatingInput rating)
 {
     try
     {
         userRatingService.AddOrUpdateUserRating(rating);
         return(Ok());
     }
     catch (NotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
 }
Exemple #2
0
        public void AddOrUpdateUserRating(UserRatingInput userRating)
        {
            var movieExists = moviesRepository.GetMovies().Any(m => m.Id == userRating.MovieId);

            if (movieExists == false)
            {
                throw new NotFoundException("Invalid movie");
            }

            var userExists = moviesRepository.GetUsers().Any(u => u.Id == userRating.UserId);

            if (userExists == false)
            {
                throw new NotFoundException("Invalid user");
            }

            moviesRepository.AddOrUpdateUserRating(
                new UserRating()
            {
                UserId  = userRating.UserId,
                MovieId = userRating.MovieId,
                Rating  = userRating.Rating
            });
        }