Beispiel #1
0
        /// <summary>
        /// Method to delete a Match
        /// </summary>
        /// <param name="idMatch">Match of the game</param>
        /// <returns>If the match was deleted</returns>
        public bool DeleteMatch(int idMatch)
        {
            bool isDeleteMatch = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    Match match = new Match();
                    match = db.Match.SingleOrDefault(matchSearch => matchSearch.idMatch == idMatch);
                    if (match != null)
                    {
                        db.Match.Remove(match);
                        db.SaveChanges();
                        isDeleteMatch = true;
                    }
                }
                catch (EntityException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(isDeleteMatch);
        }
Beispiel #2
0
        /// <summary>
        /// Method to register a game
        /// </summary>
        /// <param name="match">Match data</param>
        /// <returns>If the game was registered correctly</returns>
        public int RegisterMatch(Match match)
        {
            int idMatch = 0;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    db.Match.Add(match);
                    db.SaveChanges();
                    idMatch = match.idMatch;
                }

                catch (DbEntityValidationException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
                catch (DbUpdateException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(idMatch);
        }
Beispiel #3
0
        /// <summary>
        /// Method to delete a report
        /// </summary>
        /// <param name="nickname">Nickname of the player</param>
        /// <returns>If the report was deleted</returns>
        public bool DeleteReport(string nickname)
        {
            bool isDeleteReport = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    ReportMisConduct report = new ReportMisConduct();
                    report = db.ReportMisConduct.SingleOrDefault(reportSearch => reportSearch.idReportedPlayer == nickname);
                    if (report != null)
                    {
                        db.ReportMisConduct.Remove(report);
                        db.SaveChanges();
                        isDeleteReport = true;
                    }
                }
                catch (EntityException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(isDeleteReport);
        }
Beispiel #4
0
        /// <summary>
        /// Method to remove Players from the Match
        /// </summary>
        /// <param name="idMatch">Match identifier</param>
        /// <param name="players">Players from the Match</param>
        /// <returns>If players were removed from the Match</returns>
        public bool DeletePlayerMatch(int idMatch, List <Player> players)
        {
            bool isDeletePlayerMatch = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    Match match = new Match();
                    match = db.Match.SingleOrDefault(matchSearch => matchSearch.idMatch == idMatch);
                    if (match != null)
                    {
                        foreach (Player player in players)
                        {
                            Player playerMatch = db.Player.Find(player.nickName);
                            match.Player.Remove(playerMatch);
                        }
                        db.SaveChanges();
                        isDeletePlayerMatch = true;
                    }
                }
                catch (DbEntityValidationException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(isDeletePlayerMatch);
        }
Beispiel #5
0
        /// <summary>
        /// Method to delete a player
        /// </summary>
        /// <param name="nickname">Nickname of the player</param>
        /// <returns>If the player was deleted</returns>
        public bool DeletePlayer(string nickname)
        {
            bool isDeletePlayer = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    Player player = new Player();
                    player = db.Player.SingleOrDefault(playerSearch => playerSearch.nickName == nickname);
                    if (player != null)
                    {
                        db.Player.Remove(player);
                        db.SaveChanges();
                        isDeletePlayer = true;
                    }
                }
                catch (EntityException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(isDeletePlayer);
        }
Beispiel #6
0
        /// <summary>
        /// Method to delete an account
        /// </summary>
        /// <param name="nickname">Nickname of the player</param>
        /// <returns>If the account was deleted</returns>
        public bool DeleteAccount(string nickname)
        {
            bool isDeleteAccount = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    Account account = new Account();
                    account = db.Account.SingleOrDefault(accountSearch => accountSearch.nickName == nickname);
                    if (account != null)
                    {
                        db.Account.Remove(account);
                        db.SaveChanges();
                        isDeleteAccount = true;
                    }
                }
                catch (EntityException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(isDeleteAccount);
        }
Beispiel #7
0
        /// <summary>
        /// Method to modify player data
        /// </summary>
        /// <param name="nickname">Nickname of the player</param>
        /// <param name="playerEdit">The new data of the player</param>
        /// <returns>If the player data was modified correctly</returns>
        public bool UpdatePlayer(string nickname, Player playerEdit)
        {
            bool updatePlayer = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try {
                    Player player = db.Player.SingleOrDefault(playerSearch => playerSearch.nickName == nickname);
                    if (player != null)
                    {
                        if (!string.IsNullOrWhiteSpace(playerEdit.namePlayer))
                        {
                            player.namePlayer = playerEdit.namePlayer;
                            updatePlayer      = true;
                        }
                        if (!string.IsNullOrWhiteSpace(playerEdit.lastName))
                        {
                            player.lastName = playerEdit.lastName;
                            updatePlayer    = true;
                        }
                        db.SaveChanges();
                    }
                }
                catch (DbEntityValidationException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(updatePlayer);
        }
Beispiel #8
0
        /// <summary>
        /// Method of saving a player's points
        /// </summary>
        /// <param name="nickname">Nickname of the player</param>
        /// <param name="points">Points obtained of the player</param>
        /// <returns>If the points were saved correctly</returns>
        public bool SavePoints(string nickname, int points)
        {
            bool   save   = false;
            Player player = null;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                player = db.Player.SingleOrDefault(playerSearch => playerSearch.nickName == nickname);
                player.scoreObtained += points;
                db.SaveChanges();
                save = true;
            }
            return(save);
        }
Beispiel #9
0
        /// <summary>
        /// Method to register a report
        /// </summary>
        /// <param name="report">Data report</param>
        /// <returns>If the report was registered correctly</returns>
        public bool RegisterReport(ReportMisConduct report)
        {
            bool isReport = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    db.ReportMisConduct.Add(report);
                    db.SaveChanges();
                    isReport = true;
                }
                catch (DbEntityValidationException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(isReport);
        }
Beispiel #10
0
        /// <summary>
        /// Method to register player account
        /// </summary>
        /// <param name="account">Account data</param>
        /// <param name="player">Player data</param>
        /// <returns>If the player was registered correctly</returns>
        public bool RegisterPlayer(Account account, Player player)
        {
            bool registerOk = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    db.Player.Add(player);
                    db.Account.Add(account);
                    db.SaveChanges();
                    registerOk = true;
                }
                catch (DbEntityValidationException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(registerOk);
        }
Beispiel #11
0
        /// <summary>
        /// Method to delete an account
        /// </summary>
        /// <param name="nickname">Nickname of the player</param>
        /// <returns>If the account was deleted successfully</returns>
        public bool DeleteAccountPlayer(string nickname)
        {
            bool isDeletePlayer = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    Player player = db.Player.SingleOrDefault(playerSearch => playerSearch.nickName == nickname);
                    if (player != null)
                    {
                        player.statusPlayer = "Inactive";
                        db.SaveChanges();
                        isDeletePlayer = true;
                    }
                }
                catch (DbEntityValidationException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(isDeletePlayer);
        }
Beispiel #12
0
        /// <summary>
        /// Method to modify the player's email
        /// </summary>
        /// <param name="email">The email of the player</param>
        /// <param name="idAccount">The account identifier</param>
        /// <returns>If the email was modified correctly</returns>
        public bool UpdateEmail(string email, int idAccount)
        {
            bool updateEmail = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    Account account = db.Account.SingleOrDefault(accountSearch => accountSearch.idAccount == idAccount);
                    if (account != null)
                    {
                        account.email = email;
                        db.SaveChanges();
                        updateEmail = true;
                    }
                }
                catch (DbEntityValidationException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(updateEmail);
        }
Beispiel #13
0
        /// <summary>
        /// Method to change account password
        /// </summary>
        /// <param name="email">Email of the player</param>
        /// <param name="newPassword">The new password</param>
        /// <returns>If the password was changed correctly</returns>
        public bool ChangePassword(string email, string newPassword)
        {
            bool update = false;

            using (HangmanGameContext db = new HangmanGameContext())
            {
                try
                {
                    Account account = db.Account.SingleOrDefault(accountSearch => accountSearch.email == email);
                    if (account != null)
                    {
                        account.passwordAccount = newPassword;
                        db.SaveChanges();
                        update = true;
                    }
                }
                catch (DbEntityValidationException exception)
                {
                    TelegramBot.SendToTelegram(exception);
                    LogException.Log(this, exception);
                }
            }
            return(update);
        }