예제 #1
0
 public ActionResult Create()
 {
     var opponents =
         Global.Players.Where(
             p => !string.Equals(p.Username, User.Identity.Name, StringComparison.CurrentCultureIgnoreCase))
             .OrderBy(p => p.Name);
     var match = new NewMatch
     {
         Opponents = new SelectList(opponents, "Id", "Name"),
         PossibleOutcomes = new SelectList(MatchOutcome.PossibleOutcomes, "Id", "Description")
     };
     return View(match);
 }
예제 #2
0
        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);
        }