Exemplo n.º 1
0
        //checked
        #region GameFrame
        public int AddGameFrame(GameFrameModel gf) // returns 1 if the insertion was successful //-1 if parameters are incoherent//-2 if the GF already exists// checked//
        {
            var       cont = new SeniorLinqDataContext();
            GameFrame temp = new GameFrame();

            if (gf.MinPlayers <= gf.MaxPlayers && gf.MinStrategies <= gf.MaxStrategies)
            {
                var query1 = (from gfs in cont.GameFrames where gfs.Title == gf.Title select gfs).SingleOrDefault();
                if (query1 == null)
                {
                    temp.Title         = gf.Title;
                    temp.MinPlayers    = gf.MinPlayers;
                    temp.MaxPlayers    = gf.MaxPlayers;
                    temp.MinStrategies = gf.MinStrategies;
                    temp.MaxStrategies = gf.MaxStrategies;
                    cont.GameFrames.InsertOnSubmit(temp);
                    cont.SubmitChanges();
                    var query = (from gff in cont.GameFrames where gff.Title == temp.Title select gff.Title).SingleOrDefault();
                    if (query != null)
                    {
                        return(1);
                    }
                }
                return(-2);
            }
            return(-1);
        }
Exemplo n.º 2
0
        public GameFrameModel RetreiveGameFrame(string title)// returns a gameframe if found , otherwise null ///checked
        {
            var cont  = new SeniorLinqDataContext();
            var query = (from gff in cont.GameFrames where gff.Title == title select gff).SingleOrDefault();

            if (query != null)
            {
                GameFrameModel gf = new GameFrameModel();
                gf.Title         = query.Title;
                gf.MinPlayers    = query.MinPlayers;
                gf.MaxPlayers    = query.MaxPlayers;
                gf.MinStrategies = query.MinStrategies;
                gf.MaxStrategies = query.MaxStrategies;
                return(gf);
            }
            return(null);
        }
Exemplo n.º 3
0
        public int UpdateGameFrame(GameFrameModel edited)
        {
            if (edited.MinPlayers > edited.MaxPlayers && edited.MinStrategies > edited.MaxStrategies)
            {
                return(-1);
            }
            var cont  = new SeniorLinqDataContext();
            var query = (from gfs in cont.GameFrames where gfs.Title == edited.Title select gfs).SingleOrDefault();

            if (query != null)
            {
                GameFrameModel temp = new GameFrameModel();
                query.MaxPlayers    = edited.MaxPlayers;
                query.MaxStrategies = edited.MaxStrategies;
                query.MinPlayers    = edited.MinPlayers;
                query.MinStrategies = edited.MinStrategies;
                cont.SubmitChanges();
                return(1);
            }
            return(-1);
        }
Exemplo n.º 4
0
        public List <GameFrameModel> RetreiveFreeGameFrame()
        {
            var cont     = new SeniorLinqDataContext();
            var allGFs   = (from gfs in cont.GameFrames select gfs.Title).ToList();
            var allGames = (from games in cont.Games select games.Title).ToList();
            var result   = allGFs.Except(allGames);
            List <GameFrameModel> result2 = new List <GameFrameModel>();

            foreach (string title in result)
            {
                GameFrameModel temp = new GameFrameModel();
                var            x    = (from gfs in cont.GameFrames where gfs.Title == title select gfs).SingleOrDefault();
                temp.Title         = x.Title;
                temp.MinStrategies = x.MinStrategies;
                temp.MinPlayers    = x.MinPlayers;
                temp.MaxPlayers    = x.MaxPlayers;
                temp.MaxStrategies = x.MaxStrategies;
                result2.Add(temp);
            }
            return(result2);
        }
Exemplo n.º 5
0
        public List <GameFrameModel> GameByNumPlayer(int nop)
        {
            var cont = new SeniorLinqDataContext();
            List <GameFrameModel> gameframemodels = new List <GameFrameModel>();

            if (nop < 4)
            {
                var query = (from gf in cont.GameFrames where gf.MinPlayers == gf.MaxPlayers && gf.MinPlayers == nop select gf).ToList();// all gameframes with nop players
                List <GameFrameModel> gamemodels = new List <GameFrameModel>();
                for (int i = 0; i < query.Count; i++)
                {
                    GameFrameModel Model1 = new GameFrameModel();
                    Model1.Title         = query[i].Title;
                    Model1.MaxPlayers    = query[i].MaxPlayers;
                    Model1.MaxStrategies = query[i].MaxStrategies;
                    Model1.MinPlayers    = query[i].MinPlayers;
                    Model1.MinStrategies = query[i].MinStrategies;
                    gameframemodels.Add(Model1);
                }
            }
            else
            {
                var query = (from gf in cont.GameFrames where gf.MaxPlayers > 3 select gf).ToList();//all N gameframes
                for (int i = 0; i < query.Count; i++)
                {
                    GameFrameModel Model1 = new GameFrameModel();
                    Model1.Title         = query[i].Title;
                    Model1.MaxPlayers    = query[i].MaxPlayers;
                    Model1.MaxStrategies = query[i].MaxStrategies;
                    Model1.MinPlayers    = query[i].MinPlayers;
                    Model1.MinStrategies = query[i].MinStrategies;
                    gameframemodels.Add(Model1);
                }
            }
            return(gameframemodels);
        }