示例#1
0
        public async Task <IActionResult> DeleteFeedback([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(ModelState));
            }
            var newReview = Mapper.Map <MovieReview>(review);

            newReview.CustomerMailAddress = User.Identity.Name;
            try
            {
                _repository.DeleteMovieReview(newReview);
                if (await _repository.SaveChangesAsync())
                {
                    return(Json($"/api/movies/{review.MovieId}/feedback"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

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