示例#1
0
        public async Task <IActionResult> OnGetAsync(string statusMessage)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToPage("/Account/Login"));
            }

            var wishlist = await _context.GetWishlistAsync(user);

            var games = _context.WishlistGames.Include(x => x.Game).Where(x => x.WishlistId == wishlist.Id);

            if (games == null)
            {
                return(Page());
            }

            if (!string.IsNullOrEmpty(Search))
            {
                games = games.Where(x => x.Game.Title.Contains(Search.Trim()));
            }

            Games = await games.ToListAsync();

            StatusMessage = !string.IsNullOrEmpty(statusMessage) ? statusMessage : "";
            return(Page());
        }
示例#2
0
        public async Task <IActionResult> OnPostWishlistAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToPage("/Account/Login"));
            }

            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 wishlist = await _context.GetWishlistAsync(user);

            if (wishlist == null)
            {
                StatusMessage = $"Error: An error occurred while getting your wishlist.";
                return(RedirectToPage());
            }

            if (await _context.DoesGameExistInWishlistAsync(wishlist, Game))
            {
                StatusMessage = $"Error: This game is already on your wishlist.";
                return(RedirectToPage());
            }

            if (await _context.AddToWishlistAsync(wishlist, Game))
            {
                StatusMessage = $"'{Game.Title}' has been added to your wishlist.";
                return(RedirectToPage());
            }
            else
            {
                StatusMessage = $"Error: We were unable to add that game to your wishlist.";
                return(RedirectToPage());
            }
        }