Beispiel #1
0
        public async Task <IActionResult> ReviewBook(string Id)
        {
            if (Id == null)
            {
                ViewBag.ErrorTitle   = $"You are tring to Review a book with invalid state!";
                ViewBag.ErrorMessage = "Book Id cannot be null!";
                return(View("Error"));
            }
            var book = await _bookService.FindByIdAsync(Id);

            if (book == null)
            {
                ViewBag.ErrorTitle = $"You are tring to CheckOut a book with invalid model state!";
                return(View("Error"));
            }
            var books = await _bookService.GetAllSameBooks(Id);

            var user = await _userManager.GetUserAsync(User);

            if (user.Id == null)
            {
                ViewBag.ErrorTitle   = $"You are tring to Review a book with invalid User state!";
                ViewBag.ErrorMessage = "User Id cannot be null!";
                return(View("Error"));
            }

            var canUserReview = await _reviewService.CheckIfUserCanReview(user.Id, Id);

            var vm = MapToViewModel.MapToReviewViewModel(books.First(), user.Id);

            vm.Id     = Id;
            vm.UserId = user.Id;

            vm.CanReview = canUserReview;
            vm.Comments  = await _reviewService.GetAllCommentsForBook(vm.Title);

            return(View("ReviewBook", vm));
        }