Example #1
0
        public async Task <IActionResult> Delete([FromBody] MovieCastViewModel castMember)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _repository.DeleteMovieCast(Mapper.Map <MovieCast>(castMember));
            if (await _repository.SaveChangesAsync())
            {
                return(Ok($"api/moviecast/"));
            }
            return(BadRequest("Failed to save changes to the database"));
        }
Example #2
0
        public async Task <IActionResult> LeaveFeedback([FromBody] MovieReviewViewModel review)
        {
            var hasSeen = _context.Watchhistory.Where(r => r.CustomerMailAddress == User.Identity.Name).FirstOrDefault(r => r.MovieId == review.MovieId);

            if (!ModelState.IsValid && hasSeen == null)
            {
                return(BadRequest());
            }
            if (review.Review.Length < 10 || review.Review.Length > 500)
            {
                return(BadRequest("The length of your review is too long or too short (min 10 & max 500 characters)"));
            }
            if (review.Rating < 1 || review.Rating > 10)
            {
                return(BadRequest("Rating must be between 1 and 10"));
            }

            var newReview = Mapper.Map <MovieReview>(review);

            newReview.CustomerMailAddress = User.Identity.Name;
            try
            {
                _repository.AddReviewToMovie(newReview);
                if (await _repository.SaveChangesAsync())
                {
                    return(Created($"/api/movies/{review.MovieId}/feedback",
                                   Mapper.Map <MovieReviewViewModel>(newReview)));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            return(BadRequest("Failed to save changes to the database"));
        }