Пример #1
0
        public int AddGamePlayer(GamePlayerModel player) // returns -1 if the username already exists//-2 if there is no game // 1 success
        {
            var cont   = new SeniorLinqDataContext();
            var query2 = (from gps in cont.Users where gps.Username == player.UserName select gps).SingleOrDefault();

            if (query2 == null)
            {
                return(-1);
            }
            var query1 = (from gameplayers in cont.Gameplayers where gameplayers.Username == player.UserName && gameplayers.GID == player.GID select gameplayers).SingleOrDefault();//make sure that the game doesn't exists

            if (query1 == null)
            {
                var gamechecker = (from game in cont.Games where game.GID == player.GID select game).SingleOrDefault();
                if (gamechecker == null)
                {
                    return(-2);
                }
                Gameplayer temp = new Gameplayer();
                temp.GID      = player.GID;
                temp.Username = player.UserName;
                cont.Gameplayers.InsertOnSubmit(temp);
                cont.SubmitChanges();
                return(1);
            }
            return(-1);
        }
Пример #2
0
        public List <GamePlayerModel> RetreiveAllGamePlayersByPlayer(string usrname)
        {
            var cont = new SeniorLinqDataContext();
            List <GamePlayerModel> gameplayers = new List <GamePlayerModel>();
            var query = (from gp in cont.Gameplayers where gp.Username == usrname select gp).ToList();

            for (int i = 0; i < query.Count; i++)
            {
                GamePlayerModel gpm = new GamePlayerModel();
                gpm.GID      = query[i].GID;
                gpm.UserName = query[i].Username;
                gameplayers.Add(gpm);
            }
            return(gameplayers);
        }
Пример #3
0
        //public int DeleteGamePlayer(String uname)
        //{
        //    var cont = new SeniorLinqDataContext();
        //    var query = (from gp in cont.Gameplayers where gp.Username == uname select gp).SingleOrDefault();
        //    cont.Gameplayers.DeleteOnSubmit(query);
        //    cont.SubmitChanges();
        //    var q = (from palyer in cont.Gameplayers where palyer.Username == uname select palyer).SingleOrDefault();
        //    if (q == null)
        //        return 1;
        //    else return -1;
        //}
        public List <GamePlayerModel> RetreiveGamePlayers(int gid)//retruns all found GPs if found // null List otherwise//checked
        {
            var cont  = new SeniorLinqDataContext();
            var query = (from gp in cont.Gameplayers where gp.GID == gid select gp).ToList();

            if (query != null)//found associated players
            {
                List <GamePlayerModel> gpm = new List <GamePlayerModel>();
                for (int i = 0; i < query.Count; i++)
                {
                    GamePlayerModel g = new GamePlayerModel();
                    g.GID      = query[i].GID;
                    g.UserName = query[i].Username;
                    gpm.Add(g);
                    cont.SubmitChanges();
                }
                return(gpm);
            }
            return(null);
        }