Ejemplo n.º 1
0
        private void WriteUsernameToDb(ClientObject client)
        {
            try
            {
                if (client == null)
                {
                    return;
                }
                using (var db = new ChessDataBaseDataContext())
                {
                    if (client.Username.Length > 21 || client.Username.Length == 0)
                    {
                        return;
                    }
                    var newPlayer = new T_User
                    {
                        Nickname = client.Username
                    };

                    db.T_Users.InsertOnSubmit(newPlayer);
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Console.Write("WriteUsernameToDb(): ");
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
        }
Ejemplo n.º 2
0
        private T_Game NewGameToDb()
        {
            if (server.clients.Count != 2)
            {
                return(null);
            }

            T_Game _game = new T_Game();

            try
            {
                using (var db = new ChessDataBaseDataContext())
                {
                    var user = db.T_Users.Select(q => q).ToArray();

                    foreach (var u in user)
                    {
                        _game =
                            db.T_Games.FirstOrDefault(q => q.Black == u.Id && u.Nickname == server.clients[1].Username);
                    }

                    if (_game != null)
                    {
                        return(_game);
                    }

                    var newGame = new T_Game();

                    foreach (var cl in server.clients)
                    {
                        foreach (var u in user)
                        {
                            if (cl.Username == u.Nickname && cl.WhoIam == "w")
                            {
                                newGame.White = u.Id;
                            }
                            if (cl.Username == u.Nickname && cl.WhoIam == "b")
                            {
                                newGame.Black = u.Id;
                            }
                        }
                    }

                    db.T_Games.InsertOnSubmit(newGame);
                    db.SubmitChanges();
                    _game = newGame;
                    return(_game);
                }
            }
            catch (Exception ex)
            {
                Console.Write("NewGameToDb(): ");
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
            return(null);
        }
Ejemplo n.º 3
0
        private void AddStepGame(string step, T_Game game)
        {
            try
            {
                if (game == null)
                {
                    return;
                }
                using (var db = new ChessDataBaseDataContext())
                {
                    var stepArray = step.ToCharArray();
                    var count     = db.T_Courses.Count(q => q.GameID == game.Id) + 1;
                    var newStep   = new T_Course
                    {
                        Course = step,
                        GameID = game.Id,
                        Number = count
                    };
                    if (stepArray[0] == 'w')
                    {
                        newStep.WhoGone = game.White;
                    }
                    if (stepArray[0] == 'b')
                    {
                        newStep.WhoGone = game.Black;
                    }

                    db.T_Courses.InsertOnSubmit(newStep);
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Console.Write("AddStepGame(): ");
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
        }