public async Task <IActionResult> OnGetAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(RedirectToPage("/Account/Login")); } Game = await _context.GetGameAsync(Id); if (Game == null) { return(NotFound()); } Game.Rating = await _context.GetTotalGameRatingAsync(Game); CanReview = await _context.DoesUserOwnGameAsync(user, Game); Reviews = await _context.GetGameReviewsAsync(Game); Review = Reviews.FirstOrDefault(r => r.Reviewer == user); HasReview = Review == null ? false : true; return(Page()); }
public async Task <IActionResult> OnPostCartAsync(Guid id) { var user = await _userManager.GetUserAsync(User); if (user == null) { return(RedirectToPage("/Account/Login")); } var game = await _context.GetGameAsync(id); if (game == null) { return(NotFound()); } if (await _context.DoesUserOwnGameAsync(user, game)) { StatusMessage = $"Error: You already own this game."; return(RedirectToPage()); } var cart = await _context.GetCartAsync(user); if (cart == null) { StatusMessage = $"Error: An error occurred while getting your cart."; return(RedirectToPage()); } if (await _context.DoesGameExistInCartAsync(cart, game)) { StatusMessage = $"Error: This game is already in your cart."; return(RedirectToPage()); } if (await _context.AddToCartAsync(cart, game)) { StatusMessage = $"'{game.Title}' has been added to your cart."; return(RedirectToPage()); } else { StatusMessage = $"Error: We were unable to add that game to your cart."; return(RedirectToPage()); } }