Ejemplo n.º 1
0
        public async Task <IActionResult> Details(ReviewListViewModel review, int id)
        {
            // If the review is valid
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                var userId = user.Id;
                // A new instance of ReviewListViewModel that holds the info from the parameter is made
                var newReview = new ReviewListViewModel()
                {
                    BookId    = id,
                    AccountId = user.Id,
                    Comment   = review.Comment,
                    Rating    = review.Rating
                };
                // The instance is added to the database through the sevice layer
                _reviewService.AddReviewToDB(newReview);
                return(RedirectToAction("Details", "Book", new { id = id }));
            }
            return(RedirectToAction("Details", "Book", new { id = id }));
        }