Пример #1
0
        public async Task <bool> AddBookReviewAsync(string id, AddReviewResource resource)
        {
            var result = await _libraryClient
                         .ExternalPostApiResultAsync(string.Format(_serviceUrl.Value.AddReview, id),
                                                     JsonConvert.SerializeObject(resource),
                                                     _headers);

            return(result.StatusCode == StatusCodes.Status201Created);
        }
Пример #2
0
 public async Task AddReviewAsync(string bookId, AddReviewResource resource)
 {
     var review = new BookReview
     {
         BookId        = bookId,
         ReviewComment = resource.ReviewComment,
         ReviewedBy    = _tenantContext.User
     };
     await _dbRepo.AddAsync(review);
 }
Пример #3
0
        public async Task <IActionResult> PostAsync(string id, [FromBody] AddReviewResource input)
        {
            try
            {
                if (input == null)
                {
                    return(BadRequest("Invalid input!"));
                }

                await _reviewService.AddReviewAsync(id, input);

                return(StatusCode(StatusCodes.Status201Created));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #4
0
        public ActionResult Review(string bookId, IFormCollection collection)
        {
            try
            {
                var review = new AddReviewResource
                {
                    ReviewComment = collection["ReviewComment"].ToString()
                };
                var isReviewAdded = _bookService.AddBookReviewAsync(bookId, review).Result;

                if (isReviewAdded)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                return(View());
            }
            catch
            {
                return(View());
            }
        }