Exemple #1
0
        /// <summary>
        /// Retrieve player information
        /// </summary>
        /// <param name="email">Player's email</param>
        /// <returns></returns>
        public PlayerScoreData GetWaitingPlayerData(string email)
        {
            PlayerScoreData playerData = new PlayerScoreData();

            using (MatixDataDataContext matixData = new MatixDataDataContext())
            {
                var query = from PlayersHistories in matixData.PlayersHistories
                            where
                            PlayersHistories.Player.Email == email
                            group new { PlayersHistories.Player, PlayersHistories } by new
                {
                    PlayersHistories.Player.NickName
                } into g
                    select new
                {
                    g.Key.NickName,
                    Games      = g.Count(p => p.PlayersHistories.GameId != 0),
                    Winnings   = g.Count(p => p.PlayersHistories.Win == true),
                    TotalScore = (int?)g.Sum(p => p.PlayersHistories.Score)
                };

                foreach (var p in query)
                {
                    playerData.NickName           = p.NickName;
                    playerData.NumberOfWinnings   = p.Winnings;
                    playerData.TotalNumberOfGames = p.Games;
                    playerData.TotalScore         = (int)p.TotalScore;
                }
            }

            return(playerData);
        }
Exemple #2
0
        /// <summary>
        /// Add a new player record to the database
        /// </summary>
        /// <param name="firstName">User first name</param>
        /// <param name="lastName">User last name</param>
        /// <param name="nickName">The user nick name</param>
        /// <param name="email">The user email address</param>
        /// <param name="passwordHash">A hash string generated from the user password and some salt </param>
        public void AddPlayer(string firstName, string lastName, string nickName, string email, string passwordHash)
        {
            logger.Info("AddPlayer");
            try
            {
                using (MatixDataDataContext matixData = new MatixDataDataContext())
                {
                    Player player = new Player
                    {
                        CreateTime   = DateTime.Now,
                        FirstName    = firstName,
                        LastName     = lastName,
                        NickName     = nickName,
                        Email        = email,
                        PasswordHash = passwordHash
                    };

                    matixData.Players.InsertOnSubmit(player);
                    matixData.SubmitChanges();
                }
            }
            catch (System.Exception ex)
            {
                logger.ErrorFormat("Exception on AddPlayer - {0}", ex);
                throw new Invalid​Operation​Exception("Add Player operation Failed");
            }
        }
Exemple #3
0
        /// <summary>
        /// Create a new record that a user logged in to the server
        /// </summary>
        /// <param name="email">User email address</param>
        /// <param name="passwordHash"></param>
        /// <returns></returns>
        public bool PlayerLogin(string email, string passwordHash, string ip)
        {
            try
            {
                using (MatixDataDataContext matixData = new MatixDataDataContext())
                {
                    long id    = 0;
                    var  query = from player in matixData.Players
                                 where player.Email == email
                                 select player;

                    foreach (Player p in query)
                    {
                        id = p.PlayerId;
                    }

                    PlayersLogin login = new PlayersLogin
                    {
                        PlayerId  = id,
                        LoginTime = DateTime.Now,
                        IPAddress = ip
                    };

                    matixData.PlayersLogins.InsertOnSubmit(login);
                    matixData.SubmitChanges();
                }
            }
            catch (System.Exception ex)
            {
                logger.ErrorFormat("Exception on AddPlayer - {0}", ex);
                throw new Invalid​Operation​Exception("Add Player operation Failed");
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Query the Players table and get the record id for the requested email
        /// </summary>
        /// <param name="matixData">Open data context</param>
        /// <param name="email">requested email</param>
        /// <returns></returns>
        private long GetPlayerId(MatixDataDataContext matixData, string email)
        {
            var query = (from player in matixData.Players
                         where player.Email == email
                         select new { player.PlayerId }).Single();

            return(query.PlayerId);
        }
Exemple #5
0
        /// <summary>
        /// Check whether an email and password
        /// </summary>
        /// <param name="email"></param>
        /// <param name="passwordHash"></param>
        /// <returns></returns>
        public bool CheckEmailAndPasswordHash(string email, string passwordHash)
        {
            logger.InfoFormat("CheckEmailAndPasswordHash Email: {0}, Pass: {1}", email, passwordHash);

            bool exists = false;

            using (MatixDataDataContext matixData = new MatixDataDataContext())
            {
                exists = matixData.Players.Any(u => u.Email == email && u.PasswordHash == passwordHash);
            }

            return(exists);
        }
Exemple #6
0
        /// <summary>
        /// Check whether an email exists in the database
        /// </summary>
        /// <param name="email">The user email address</param>
        /// <returns>True if the email exists otherwise false</returns>
        public bool IsPlayerEmailExist(string email)
        {
            logger.Info("IsPlayerEmailExist");

            bool exists = false;

            using (MatixDataDataContext matixData = new MatixDataDataContext())
            {
                exists = matixData.Players.Any(u => u.Email == email);
            }

            return(exists);
        }
Exemple #7
0
        /// <summary>
        /// Get the user nick name
        /// </summary>
        /// <param name="email">User email address</param>
        /// <returns>The nick name string</returns>
        public string GetPlayerNickName(string email)
        {
            logger.InfoFormat("GetPlayerNickName Email: {0}", email);

            string nickName = "";

            using (MatixDataDataContext matixData = new MatixDataDataContext())
            {
                var query = from player in matixData.Players
                            where player.Email == email
                            select player;

                foreach (Player p in query)
                {
                    nickName = p.NickName;
                }
            }

            return(nickName);
        }
Exemple #8
0
        public bool CreateNewGameTask(string horizontalEmail, string verticalEmail, string boardXml)
        {
            using (MatixDataDataContext matixData = new MatixDataDataContext())
            {
                long horizontalPlayerId = GetPlayerId(matixData, horizontalEmail);
                long verticalPlayerId   = GetPlayerId(matixData, verticalEmail);

                Game game = new Game
                {
                    CreateTime         = DateTime.Now,
                    HorizontalPlayerId = horizontalPlayerId,
                    VerticalPlayerId   = verticalPlayerId,
                    CellsMatrix        = XElement.Parse(boardXml),
                };

                matixData.Games.InsertOnSubmit(game);
                matixData.SubmitChanges();
            }



            return(true);
        }
Exemple #9
0
        /// <summary>
        /// Update user information in the database
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="nickName"></param>
        /// <returns></returns>
        public bool UpdatePlayerInformation(string firstName, string lastName, string nickName)
        {
            using (MatixDataDataContext matixData = new MatixDataDataContext())
            {
                var query = from player in matixData.Players
                            where player.PlayerId == 11000
                            select player;

                foreach (Player p in query)
                {
                }

                try
                {
                    matixData.SubmitChanges();
                }
                catch (System.Exception ex)
                {
                    logger.ErrorFormat("Exception on UpdatePlayerInformation - {0}", ex);
                }
            }

            return(true);
        }