Ejemplo n.º 1
0
        private bool prepareVGWGameContext(ref vgw_game vgwGame, GameViewModel gameViewModel, int iUserId)
        {
            try
            {

                ICollection<vgw_game_platform_xref> availableOnPlatforms;
                ICollection<vgw_game_difficulty_level_xref> difficultyLevels;

                if (vgwGame.GAMEID > 0)
                {
                    availableOnPlatforms = getGamePlatformXref(vgwGame.GAMEID);
                    difficultyLevels = getGameDifficultyLevelXref(vgwGame.GAMEID);
                }
                else
                {
                    availableOnPlatforms = new List<vgw_game_platform_xref>();
                    difficultyLevels = new List<vgw_game_difficulty_level_xref>();
                }

                vgwGame.GAMENAME = gameViewModel.GAMENAME;
                vgwGame.GENREID = gameViewModel.GENREID;
                vgwGame.SORTORDER = gameViewModel.SORTORDER;
                vgwGame.CANBEPLAYEDBYTEAM = gameViewModel.CANBEPLAYEDBYTEAM;
                vgwGame.ISACTIVE = gameViewModel.ISACTIVE;
                vgwGame.RELEASEDATE = gameViewModel.RELEASEDATE;
                vgwGame.LASTUPDATEDDATE = DateTime.Now;
                vgwGame.LASTUPDATEDBYUSERID = iUserId;

                if (gameViewModel.GAMEIMAGE != null && gameViewModel.GAMEIMAGE.GAMEIMAGEBINARY != null)
                {
                    vgwGame.GAMEIMAGE = gameViewModel.GAMEIMAGE.GAMEIMAGEBINARY;
                }

                int iPlatformId;
                if (gameViewModel.SELECTEDPLATFORMS == null)
                {
                }
                else
                {
                    foreach (int platformID in gameViewModel.SELECTEDPLATFORMS)
                    {
                        iPlatformId = platformID;
                        if (availableOnPlatforms.Where(p => p.PLATFORMID == iPlatformId).Count() == 0)
                        {
                            vgw_game_platform_xref platformGameXref = new vgw_game_platform_xref();
                            platformGameXref.GAMEID = vgwGame.GAMEID;
                            platformGameXref.ISACTIVE = true;
                            platformGameXref.LASTUPDATEDDATE = DateTime.Now;
                            platformGameXref.LASTUPDATEDUSERID = iUserId;
                            platformGameXref.PLATFORMID = iPlatformId;
                            availableOnPlatforms.Add(platformGameXref);
                        }
                    }
                }

                int iDifficultyLevelId;
                int iDifficultyLevelSortOrder = 1;
                if (gameViewModel.SELECTEDLEVELS == null)
                {
                }
                else
                {
                    foreach (int difficultyLevelId in gameViewModel.SELECTEDLEVELS)
                    {
                        iDifficultyLevelId = difficultyLevelId;
                        if (difficultyLevels.Where(d => d.DIFFICULTYLEVELID == iDifficultyLevelId).Count() == 0)
                        {
                            vgw_game_difficulty_level_xref gameDifficultyLevelXref = new vgw_game_difficulty_level_xref();
                            gameDifficultyLevelXref.DIFFICULTYLEVELID = iDifficultyLevelId;
                            gameDifficultyLevelXref.GAMEID = vgwGame.GAMEID;
                            gameDifficultyLevelXref.LASTUPDATEDBYUSERID = iUserId;
                            gameDifficultyLevelXref.LASTUPDATEDDATE = DateTime.Now;
                            gameDifficultyLevelXref.SORTORDER = iDifficultyLevelSortOrder;
                            iDifficultyLevelSortOrder++;
                            difficultyLevels.Add(gameDifficultyLevelXref);
                        }
                    }
                }

                vgwGame.AVAILABLEONPLATFORMS = availableOnPlatforms;
                vgwGame.DIFFICULTYLEVELS = difficultyLevels;
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
Ejemplo n.º 2
0
        public bool SaveGame(GameViewModel gameViewModel, int iUserId, ref int gameId)
        {
            vgw_game vgwGame;

            if (gameViewModel.GAMEID > 0)
            {
                vgwGame = GetByGameId(gameViewModel.GAMEID);
                if (!prepareVGWGameContext(ref vgwGame, gameViewModel, iUserId))
                {
                    return false;
                }
            }
            else
            {
                vgwGame = new vgw_game();
                if (prepareVGWGameContext(ref vgwGame, gameViewModel, iUserId))
                {
                    dbCon.vgw_game.Add(vgwGame);
                }
                else
                {
                    return false;
                }

            }

            int result = dbCon.SaveChanges();
            if (result > 0)
            {
                gameId = vgwGame.GAMEID;
                return true;
            }
            else
            {
                return false;
            }
        }