public MatchResultViewModel(MatchResult result) { Player = result.Player.FullName; Innings = result.Innings; DefensiveShots = result.DefensiveShots; Wins = result.Wins; }
public virtual void AddResult(MatchResult result) { Arg.Require(Players.Where(p => p.Player == result.Player).Any(), "The match result must apply to one of this match's players"); if (!Results.Contains(result)) { result.Match = this; Results.Add(result); } }
private void UpdateMatchFromViewModel(UpdateMatchViewModel viewModel, Match match, User player1, User player2) { if (match.IsComplete) { var results = match.Results.ToList(); foreach (var result in results) { repository.Delete(result); } match.Results.Clear(); } match.Winner = viewModel.Winner == player1.Id ? player1 : player2; match.IsComplete = true; match.IsForfeit = viewModel.IsForfeit; if (!match.IsForfeit) { match.DatePlayed = DateTime.Parse(viewModel.Date + " " + viewModel.Time); var matchResult = new MatchResult(player1, viewModel.Player1Innings, viewModel.Player1DefensiveShots, viewModel.Player1Wins); match.AddResult(matchResult); matchResult = new MatchResult(player2, viewModel.Player2Innings, viewModel.Player2DefensiveShots, viewModel.Player2Wins); match.AddResult(matchResult); } // set meet to complete if all matches are complete var meet = match.Meet; meet.IsComplete = !meet.Matches.Where(m => !m.IsComplete).Any(); // must do this because EF is stupid var d = meet.Division; }
public SkillLevelMatchResultViewModel(MatchResult matchResult, User player) : base(matchResult) { var match = matchResult.Match; Date = match.DatePlayed.Value; var myTeam = match.Players.Single(p => p.Player.Id == player.Id).Team; var opponentTeam = match.Meet.Teams.SingleOrDefault(t => t.Id != myTeam.Id); if (null != opponentTeam) { Team = opponentTeam.Name; } else { Team = "Historical"; } NetInnings = Innings - DefensiveShots; // for this we display our opponent Player = match.Players.Where(p => p.Player != player).Single().Player.FullName; }
public virtual void RemoveResult(MatchResult result) { if (Results.Contains(result)) { Results.Remove(result); result.Match = null; } }
public override void EstablishContext() { var repository = new Mock<IRepository>(); authService = AuthHelper.CreateMockAuthenticationService(); controller = new UpdateMatchController(repository.Object, authService); loggedInUser = new User("admin", "pass", "first", "last", "email"); loggedInUser.SetIdTo(3); loggedInUser.AddRole(new Role(Roles.Administrators)); authService.MockPrincipal.MockIdentity.IsAuthenticated = true; authService.MockPrincipal.MockIdentity.Name = loggedInUser.Username; var season = new Season("test", GameType.EightBall); var division = new Division("test", DateTime.Parse("1/1/2011"), season); season.AddDivision(division); var team1 = new Team("team1", division); division.AddTeam(team1); player1 = new User("player1", "test", "player1", "test", "test"); player1.SetIdTo(1); team1.AddPlayer(player1); var team2 = new Team("team2", division); division.AddTeam(team2); player2 = new User("player2", "test", "player2", "test", "test"); player2.SetIdTo(2); team2.AddPlayer(player2); var meet = new Meet(team1, team2, 1); division.Meets.Add(meet); match = new Web.Models.Match(meet, new MatchPlayer(player1, team1), new MatchPlayer(player2, team2)); match.SetIdTo(1); repository.Setup(r => r.Get<Web.Models.Match>(match.Id)).Returns(match); repository.Setup(r => r.Get<User>(player1.Id)).Returns(player1); repository.Setup(r => r.Get<User>(player2.Id)).Returns(player2); var player1Results = new List<MatchResult>(); var player2Results = new List<MatchResult>(); for (int i = 0; i < 4; i++) { var tempMatch = new Web.Models.Match(meet, new MatchPlayer(player1, team1), new MatchPlayer(player2, team2)); meet.AddMatch(tempMatch); tempMatch.DatePlayed = DateTime.Parse("8/1/2010").AddDays(i); tempMatch.IsComplete = true; var matchResult = new MatchResult(player1, 30, 0, 3); player1Results.Add(matchResult); tempMatch.AddResult(matchResult); matchResult = new MatchResult(player2, 30, 0, 3); player2Results.Add(matchResult); tempMatch.AddResult(matchResult); } repository.InitAll(new List<User> { player1, player2, loggedInUser }.AsQueryable(), loggedInUser.Roles.AsQueryable(), new List<Season> { season }.AsQueryable()); player1.UpdateSkillLevel(GameType.EightBall, repository.Object); player1SkillLevel = player1.SkillLevels.Where(sl => sl.GameType == GameType.EightBall).First().Value; player2.UpdateSkillLevel(GameType.EightBall, repository.Object); player2SkillLevel = player2.SkillLevels.Where(sl => sl.GameType == GameType.EightBall).First().Value; viewModel = new UpdateMatchViewModel() { Id = match.Id, IsForfeit = false, Player1Id = player1.Id, Player1Innings = 2, Player1DefensiveShots = 1, Player1Wins = 4, Player2Id = player2.Id, Player2Innings = 2, Player2DefensiveShots = 1, Player2Wins = 4, Winner = player1.Id, Date = "1/1/2011", Time = "06:00 PM" }; }