public async Task <IActionResult> Book(int?id, BookViewModel model) { try { //to add a review, user must be signed in if (!_signInManager.IsSignedIn(User)) { return(RedirectToAction("Login", "Account", new { returnUrl = $"/Catalogue/Book/{id}" })); } if (id == null) { return(RedirectToAction("Error", "Home")); } if (_businessService.GetProduct(id.Value) == null) { return(RedirectToAction("Error", "Home")); } model.ProductId = id.Value; var user = await _userManager.GetUserAsync(User); ViewData["productId"] = id; Review review = new Review { Date = DateTime.Now, ProductId = model.ProductId, Rating = model.NewRating, Text = model.ReviewText, UserId = user.Id }; //review can be added only if there is no other if (_businessService.GetReview(review.UserId, review.ProductId).isEmpty) { _businessService.AddReview(review); } model = _bookLoader.LoadBookModel(id.Value); return(View(model)); } catch (Exception e) { return(AlzaError.ExceptionActionResult(e)); } }