public override void Save() { System.Data.SqlClient.SqlTransaction t = SqlHelper.BeginTransaction(Config.ConnectionString); try { if (GameResultIDE != GameResultE.InProgress && GameResultIDE != GameResultE.None && GameResultIDE != GameResultE.NoResult) { if (GameResultIDE != GameResultE.WhiteBye || GameResultIDE != GameResultE.BlackBye) { Elo e = new Elo(this); e.Update(t); } if (this.Challenge.Stake > 0 && this.Challenge.Flate != 0) { UserFini.UpdateFiniTransfer(t, base.Cxt, this, this.Challenge.Stake, this.Challenge.Flate); } if (this.IsTournamentMatch) { if (this.GameResultIDE == GameResultE.Draw) { this.TournamentMatch.TournamentMatchStatusE = TournamentMatchStatusE.Draw; this.TournamentMatch.GameResultID = this.GameResultID; this.TournamentMatch.Save(t); } else { string matchID = this.TournamentMatch.TournamentMatchID.ToString(); this.TournamentMatch.GameResultID = this.GameResultID; TournamentMatches.UpdateStatus(t, base.Cxt, TournamentMatchStatusE.Finsihed, matchID, this.GameResultIDE); } this.TournamentMatch.UpdateUserPoints(t); } } base.Save(t); SqlHelper.CommitTransaction(t); if (IsFinished) { TournamentMatch.CreateChildMatchIfRequired(Cxt, this.TournamentMatch, null); } } catch (Exception ex) { SqlHelper.RollbackTransaction(t); Log.Write(Cxt, ex); } }
private static UserFini GetUpdatedUserFini(Cxt cxt, Game game, int whiteFini, int blackFini, int stake, int flate) { UserFini UserFini = new UserFini(cxt, 0); UserFini.StackFee = stake; UserFini.FlateFee = flate; UserFini.WhiteFini = whiteFini; UserFini.BlackFini = blackFini; UserFini.WhiteUserID = game.WhiteUserID; UserFini.BlackUserID = game.BlackUserID; UserFini.GameResultID = game.GameResultID; UserFini.GameID = Convert.ToInt32(game.GameID); return(UserFini); }
public static void UpdateFiniTransfer(SqlTransaction trans, Cxt cxt, Game game, int stake, int flate) { int wFini = 0, bFini = 0; bool isOpponentWhite = IsOpponentWhite(game); /// below check will be for stake fee if (game.GameResultIDE == GameResultE.WhiteWin) // if white wins then stake will be gain by white user { User WhiteUser = new User(cxt, game.WhiteUserID); wFini = WhiteUser.Fini + stake; User BlackUser = new User(cxt, game.BlackUserID); bFini = BlackUser.Fini - stake; } else if (game.GameResultIDE == GameResultE.WhiteLose) { User WhiteUser = new User(cxt, game.WhiteUserID); wFini = WhiteUser.Fini - stake; User BlackUser = new User(cxt, game.BlackUserID); bFini = BlackUser.Fini + stake; } // below check will be for flate fee UserFini UserFini = null; if (flate > 0) // +ve flate fee mean opponent will pay to challenger { if (isOpponentWhite) { User ChallengerUser = new User(cxt, game.Challenge.ChallengerUserID); bFini = bFini + flate; // +ve flate fee for paid by opponent User OpponentUser = new User(cxt, game.Challenge.OpponentUserID); wFini = wFini - flate; } else { User ChallengerUser = new User(cxt, game.Challenge.ChallengerUserID); wFini = wFini + flate; // +ve flate fee for paid by opponent User OpponentUser = new User(cxt, game.Challenge.OpponentUserID); bFini = bFini - flate; } } else // flate fee with -ve, challenger pay the opponent no matter what the result is. { if (isOpponentWhite) { User ChallengerUser = new User(cxt, game.Challenge.ChallengerUserID); bFini = bFini + flate; // -ve flate fee for paid by challenger User OpponentUser = new User(cxt, game.Challenge.OpponentUserID); wFini = wFini - flate; } else { User ChallengerUser = new User(cxt, game.Challenge.ChallengerUserID); wFini = wFini + flate; // -ve flate fee for paid by challenger User OpponentUser = new User(cxt, game.Challenge.OpponentUserID); bFini = bFini - flate; } } UserFini = GetUpdatedUserFini(cxt, game, wFini, bFini, stake, flate); UserFini.Save(trans); User.UpdateFini(trans, wFini, game.WhiteUser.UserID); User.UpdateFini(trans, bFini, game.BlackUser.UserID); }