public MatchDetail(Match match) { _match = match; var playerOne = Global.AllPlayers.Single(p => p.Id == match.PlayerOneId); PlayerOneName = string.Format("{0} {1}", playerOne.FirstName, playerOne.Surname); var delta = match.PlayerOneNewMu - match.PlayerOneOldMu; PlayerOneMuDelta = delta; PlayerOneSigmaDelta = match.PlayerOneNewSigma - match.PlayerOneOldSigma; var playerTwo = Global.AllPlayers.Single(p => p.Id == match.PlayerTwoId); PlayerTwoName = string.Format("{0} {1}", playerTwo.FirstName, playerTwo.Surname); PlayerTwoMuDelta = match.PlayerTwoNewMu - match.PlayerTwoOldMu; PlayerTwoSigmaDelta = match.PlayerTwoNewSigma - match.PlayerTwoOldSigma; if (match.ConfirmationDate == null) { Status = MatchStatus.PendingConfirmation; } else if (match.PostDate == null) { Status = MatchStatus.PendingPosting; } else { Status = MatchStatus.Posted; } }
public static int Create(Match match) { using (var connection = ConnectionFactory.GetConnection()) { return connection.Execute(CreateSql, match); } }
public static void CreateMatch(NewMatch newMatch) { var playerOne = Global.Players.Single(p => p.Id == newMatch.PlayerOneId); var playerOneRating = FindLastGoodRating(playerOne, newMatch.MatchDate); var playerTwo = Global.Players.Single(p => p.Id == newMatch.PlayerTwoId); var playerTwoRating = FindLastGoodRating(playerTwo, newMatch.MatchDate); CalculateRating(playerOneRating, playerTwoRating, newMatch.Placement); var match = new Match { MatchDate = newMatch.MatchDate, PlayerOneId = playerOneRating.Id, PlayerOneOldMu = playerOneRating.OldMu, PlayerOneOldSigma = playerOneRating.OldSigma, PlayerTwoId = playerTwoRating.Id, PlayerTwoOldMu = playerTwoRating.OldMu, PlayerTwoOldSigma = playerTwoRating.OldSigma, PlayerOneNewMu = playerOneRating.NewMu, PlayerOneNewSigma = playerOneRating.NewSigma, PlayerTwoNewMu = playerTwoRating.NewMu, PlayerTwoNewSigma = playerTwoRating.NewSigma, WinningPlayerId = newMatch.Placement == 1 ? playerOneRating.Id : playerTwoRating.Id }; lock (Global.Lock) { MatchData.Create(match); } Global.LoadAll(); var to = (playerTwo.Notifications && !string.IsNullOrWhiteSpace(playerTwo.Email)) ? playerTwo.Email : null; if (to == null) return; var subject = string.Format("{0} has submitted a match pending your approval, {1}", playerOne.Name, "http://smartpong/Matches/Pending"); var body = string.Format("Match Date: {0}, Your Result: {1}", newMatch.MatchDate, newMatch.Placement == 1 ? "Loss" : "Win"); NotificationBusiness.Send(to, subject, body); }