public async Task <IActionResult> Add([FromBody] AddReviewRequest reviewRequest) { if (reviewRequest == null || reviewRequest.Review == null) { return(BadRequest()); } var review = reviewRequest.Review; if (string.IsNullOrEmpty(review.Title)) { return(Ok(new { Success = false })); } var successfulCaptcha = await GoogleController.ValidateRecaptcha(reviewRequest.RecaptchaResponse); if (!successfulCaptcha) { return(Ok(new { Success = false })); } // now that we've successfully passed all validations, get the Author id // from the User object and add the review var googleId = GetUserGoogleId(); if (googleId == null) { return(BadRequest()); } var author = await RRRepo.GetAuthorByGoogleId(googleId); var authorsReviews = await RRRepo.GetReviewsByAuthorId(author.Id); if (authorsReviews?.FirstOrDefault(rev => rev.RestroomId == review.RestroomId) != null) { return(Ok(new { Success = false, Error = "ALREADY_EXISTS" })); } var restroom = await RRRepo.GetById(review.RestroomId); review.Author = author; review.Restroom = restroom; await RRRepo.AddReview(review); return(Ok(new { Success = true, Review = review, })); }
public async Task <IActionResult> GetById(int id) { var room = await RRRepo.GetById(id); var currentUserGoogleId = GetUserGoogleId(); Author currentAuthor = null; if (!string.IsNullOrEmpty(currentUserGoogleId)) { currentAuthor = await RRRepo.GetAuthorByGoogleId(currentUserGoogleId); } foreach (var review in room.Reviews) { // if it's their own review, don't strip the AuthorId if (review.AuthorIsAnonymous && review.AuthorId != currentAuthor?.Id) { review.Author = null; review.AuthorId = -1; } } return(Ok(room)); }