Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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());
            }
        }