public async Task <IActionResult> PutReview(string id, PutReviewModel putReviewModel) { try { if (!Guid.TryParse(id, out Guid reviewId)) { throw new GuidException("Invalid id", this.GetType().Name, "PutReview", "400"); } await _reviewRepository.PutReview(id, putReviewModel); await _movieRepository.CalculateOverallRating(putReviewModel.MovieId.ToString()); return(NoContent()); } catch (MovieMindException e) { if (e.MovieMindError.Status.Equals("404")) { return(NotFound(e.MovieMindError)); } else { return(BadRequest(e.MovieMindError)); } } }
public async Task <IActionResult> Edit(string id) { try { AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "review"); GetReviewModel getReviewModel = await _moviemindAPIService.GetModel <GetReviewModel>(id, "reviews"); List <GetMovieModel> getMovieModels = await _moviemindAPIService.GetModels <GetMovieModel>("movies"); PutReviewModel putReviewModel = new PutReviewModel { Description = getReviewModel.Description, Date = getReviewModel.Date, MovieId = getReviewModel.MovieId, Rating = getReviewModel.Rating, UserId = getReviewModel.UserId }; ViewBag.Movies = getMovieModels; return(View(putReviewModel)); } catch (MovieMindException e) { return(ErrorHelper.HandleError(e)); } }
public async Task PutReview(string id, PutReviewModel putReviewModel) { Review review = await _context.Reviews.FirstOrDefaultAsync(x => x.Id == Guid.Parse(id)); if (review == null) { throw new EntityException("Review not found", this.GetType().Name, "PutReview", "404"); } try { review.Date = putReviewModel.Date; review.Description = putReviewModel.Description; review.Rating = putReviewModel.Rating; review.MovieId = putReviewModel.MovieId; review.UserId = putReviewModel.UserId; await _context.SaveChangesAsync(); } catch (MovieMindException) { throw; } catch (Exception e) { throw new DatabaseException(e.InnerException.Message, this.GetType().Name, "PutReview", "400"); } }
[ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks public async Task <IActionResult> Edit(string id, PutReviewModel putReviewModel) { try { AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "review"); if (ModelState.IsValid) { await _moviemindAPIService.PutModel <PutReviewModel>(id, putReviewModel, "reviews"); return(Redirect("/Reviews/Details/" + id.ToString())); } return(View(putReviewModel)); } catch (MovieMindException e) { return(ErrorHelper.HandleError(e, this.View(putReviewModel))); } }