public static DataTable DeclineChallenge(Cxt cxt, int challengeID) { Challenge item = new Challenge(cxt, challengeID); item.ChallengeStatusIDE = ChallengeStatusE.Decline; item.ChallengeTypeIDE = ChallengeTypeE.Decline; item.Save(); return(Challenges.GetChallengesByRoomID(cxt, item.RoomID, item.ChallengerUserID)); }
public static DataTable DeleteChallenge(Cxt cxt, int challengeID) { Challenge item = new Challenge(cxt, challengeID); item.ChallengeStatusIDE = ChallengeStatusE.Withdraw; item.StatusIDE = StatusE.Deleted; item.Save(); return(Challenges.GetChallengesByRoomID(cxt, item.RoomID, item.ChallengerUserID)); }
public override void Save() { SqlTransaction trans = null; this.DtTournamentUsersMatch = TournamentUsers.GetTournamentUsersByTournamentID(StatusE.Active, this.Tournament.TournamentID); try { for (int i = 0; i < this.Count; i++) { trans = SqlHelper.BeginTransaction(Config.ConnectionString); TournamentMatch tournamentMatch = this[i]; this.Save(trans); Challenge Challenge = CreateChallenge(tournamentMatch); Challenge.Save(trans); Game Game = null; //if (this.teamLooseStatusE != TeamLooseStatusE.None) //{ // Game = CreateGame(this, Challenge); Game.Save(trans); //} if (this.Tournament.TournamentStartDate == new DateTime()) { this.Tournament.TournamentStartDate = DateTime.Now; this.Tournament.TournamentStartTime = DateTime.Now; this.Tournament.Save(trans); } SqlHelper.CommitTransaction(trans); trans = SqlHelper.BeginTransaction(Config.ConnectionString); //if (this.teamLooseStatusE != TeamLooseStatusE.None) //{ Elo Elo = new Elo(Game); if (Game.IsEloWhiteUpated && Game.IsEloBlackUpated) { Elo.Update(trans); } //} SqlHelper.CommitTransaction(trans); } } catch (Exception ex) { SqlHelper.RollbackTransaction(trans); Log.Write(base.Cxt, ex); } }
public static DataTable GetAcceptedChallenge(Cxt cxt, int roomID, int userID) { DataTable table = BaseCollection.ExecuteSql(InfiChess.Challenge, "SELECT TOP 1 * FROM Challenge WHERE RoomID=@p1 AND ChallengerUserID=@p2 AND ChallengeStatusID = 2 AND StatusID = 1", roomID, userID); if (table.Rows.Count > 0) { Challenge c = new Challenge(cxt, table.Rows[0]); c.ChallengeStatusIDE = ChallengeStatusE.Played; c.StatusIDE = StatusE.Inactive; c.Save(); } return(table); }
//public static void UpdateTournamentMatchStatus(Cxt cxt, int tournamentID, int tournamentMatchStatusID, string matchIDs) //{ // string[] matches = matchIDs.Split(','); // foreach (string item in matches) // { // UpdateTournamentMatchStatus(cxt, tournamentMatchStatusID, Convert.ToInt32(item)); // } //} #region Update Match Status public static void UpdateTournamentMatchStatus(Cxt cxt, TournamentMatchStatusE tournamentMatchStatusID, TournamentMatch m) { SqlTransaction t = null; Game g = null; Challenge c = null; DataTable dtMatches = TournamentMatches.GetTournamentsMatchByTournamentID(m.TournamentID); TournamentMatches matches = new TournamentMatches(cxt, dtMatches); DataTable dtGame = Games.GetAllGamesByTournamentID(cxt, m.TournamentID); DataTable dtTUser = TournamentUsers.GetTournamentUsersByTournamentID(StatusE.Active, m.TournamentID); try { if (!TournamentMatchRules.Instance.CanChangeStatus(m.TournamentMatchStatusE, tournamentMatchStatusID)) { return; } m.EloBlackBefore = (m.EloBlackBefore == 0) ? 1500 : m.EloBlackBefore; m.EloWhiteBefore = (m.EloWhiteBefore == 0) ? 1500 : m.EloWhiteBefore; m.TournamentMatchStatusE = tournamentMatchStatusID; if (GetGameResultID((TournamentMatchStatusE)tournamentMatchStatusID) != GameResultE.None) { m.GameResultIDE = GetGameResultID((TournamentMatchStatusE)tournamentMatchStatusID); } if (m.TournamentMatchStatusE == TournamentMatchStatusE.InProgress || m.IsBye || m.IsForced) { c = CreateChallenge(m); } t = SqlHelper.BeginTransaction(Config.ConnectionString); m.Save(t); if (c != null) { if (c.IsNew) { c.Save(t); } } if (m.IsBye || m.IsForced) { if (c != null) { c.ChallengeStatusIDE = ChallengeStatusE.Decline; c.StatusIDE = StatusE.Inactive; c.Save(t); } TournamentUserResult(cxt, dtTUser, m, matches, dtGame).Save(t); g = GetGame(cxt, m); if (!g.IsNew) { g.GameResultIDE = m.GameResultIDE; g.GameFlags = ""; g.Save(t); } } SqlHelper.CommitTransaction(t); switch (m.TournamentMatchStatusE) { case TournamentMatchStatusE.Draw: case TournamentMatchStatusE.WhiteBye: case TournamentMatchStatusE.BlackBye: case TournamentMatchStatusE.ForcedWhiteWin: case TournamentMatchStatusE.ForcedWhiteLose: case TournamentMatchStatusE.ForcedDraw: TournamentMatch.CreateChildMatchIfRequired(cxt, m, dtTUser); break; default: break; } } catch (Exception ex) { SqlHelper.RollbackTransaction(t); Log.Write(cxt, ex); } }