コード例 #1
0
        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,
            }));
        }
コード例 #2
0
        public async Task <IActionResult> GetCurrentUserReviews()
        {
            var googleId = GetUserGoogleId();

            if (googleId == null)
            {
                return(BadRequest());
            }

            var author = await RRRepo.GetAuthorByGoogleId(googleId);

            if (author == null)
            {
                return(BadRequest());
            }

            var reviews = await RRRepo.GetReviewsByAuthorId(author.Id);

            return(Ok(reviews));
        }