private static void CreateHtmlAllGamesString(bool isLoggedIn, bool isAdmin, List <GameHomeViewModel> games, StringBuilder sb) { for (int i = 0; i < games.Count; i++) { GameHomeViewModel game = games[i]; bool hasCardGroupOpen = i % 3 == 0; bool hasCardGroupClosed = i % 3 == 2; if (hasCardGroupOpen) { sb.Append("<div class=\"card-group\">"); } sb.Append("<div class=\"card col-4 thumbnail\">" + "<img " + "class=\"card-image-top img-fluid img-thumbnail\"" + $"onerror=\"this.src='https://i.ytimg.com/vi/{game.Trailer}/maxresdefault.jpg';\"" + $"src=\"{game.ThumbnailUrl}\">" + "<div class=\"card-body\">" + $"<h4 class=\"card-title\">{game.Title}</h4>" + $"<p class=\"card-text\"><strong>Price</strong> - {game.Price}€</p>" + $"<p class=\"card-text\"><strong>Size</strong> - {game.Size} GB</p>" + $"<p class=\"card-text\">{game.Description}</p>" + "</div>" + "<div class=\"card-footer\">"); if (isAdmin) { sb.Append( $"<a class=\"card-button btn btn-warning\" name=\"edit\" href=\"edit-game/{game.Id}\">Edit</a>" + $"<a class=\"card-button btn btn-danger\" name=\"delete\" href=\"delete-game/{game.Id}\">Delete</a>"); } if (isLoggedIn) { sb.Append( $"<a class=\"card-button btn btn-outline-primary\" name=\"info\" href=\"/game-details/{game.Id}\">Info</a>" + $"<a class=\"card-button btn btn-primary\" name=\"buy\" href=\"/buy-game/{game.Id}\">Buy</a>" + "</div>" + "</div>" ); } else { sb.Append( $"<a class=\"card-button btn btn-outline-primary\" name=\"info\" href=\"/game-details/{game.Id}\">Info</a>" + $"<a class=\"card-button btn btn-primary\" name=\"buy\" href=\"/login\">Buy</a>" + "</div>" + "</div>" ); } if (hasCardGroupClosed) { sb.Append("</div>"); } } }
public List <GameHomeViewModel> GetOwnedGames(string email) { using (GameStoreDbContext db = new GameStoreDbContext()) { User user = db .Users .Include(u => u.Orders) .ThenInclude(o => o.Games) .ThenInclude(og => og.Game) .Where(u => u.Email == email) .FirstOrDefault(); ICollection <Order> orders = user.Orders; List <GameHomeViewModel> games = new List <GameHomeViewModel>(); foreach (Order order in orders) { List <Game> gamesToAdd = order .Games .Select(og => og.Game) .ToList(); foreach (Game gameToAdd in gamesToAdd) { GameHomeViewModel gameModel = mapper.Map <GameHomeViewModel>(gameToAdd); games.Add(gameModel); } } return(games); } }