예제 #1
0
        public ShortGamesWithCategoryModel GetSameCategoryGameCards(string category)
        {
            using (DatabaseContext context = new DatabaseContext()) {
                var result = from g in context.Games
                             join gc in context.GameCategories on g.Id equals gc.GameId
                             join c in context.Categories on gc.CategoryId equals c.Id
                             where c.Name == category
                             select g;

                List <ShortGameModel> games = new List <ShortGameModel>();
                foreach (var game in result)
                {
                    ShortGameModel model = new ShortGameModel {
                        Id               = game.Id,
                        AccountId        = game.AccountId,
                        Title            = game.Title,
                        ImageFileName    = game.ImageFileName,
                        ShortDescription = game.ShortDescription,
                        Categories       = GetCategoriesNameFromGameId(game.Id)
                    };

                    games.Add(model);
                }

                return(new ShortGamesWithCategoryModel {
                    Category = category,
                    ShortGameModels = games
                });
            }
        }
예제 #2
0
        public IEnumerable <ShortGameModel> GetGamesCards(int accountId)
        {
            using (DatabaseContext context = new DatabaseContext()) {
                IEnumerable <Game> games;

                if (accountId == -1)
                {
                    games = context.Games;
                }
                else
                {
                    games = from a in context.Accounts
                            join g in context.Games on a.Id equals g.AccountId
                            where a.Id == accountId
                            select g;
                }

                List <ShortGameModel> gameCards = new List <ShortGameModel>();

                foreach (var game in games)
                {
                    ShortGameModel model = new ShortGameModel {
                        Id               = game.Id,
                        AccountId        = game.AccountId,
                        Title            = game.Title,
                        Categories       = GetCategoriesNameFromGameId(game.Id),
                        ShortDescription = game.ShortDescription,
                        ImageFileName    = game.ImageFileName
                    };

                    gameCards.Add(model);
                }

                return(gameCards);
            }
        }