コード例 #1
0
ファイル: MeetsController.cs プロジェクト: pwideman/ClubPool
 private DetailsViewModel CreateDetailsViewModel(Meet meet)
 {
     var model = new DetailsViewModel();
       model.Id = meet.Id;
       model.ScheduledWeek = meet.Week + 1;
       model.ScheduledDate = meet.Division.StartingDate.AddDays(meet.Week * 7).ToShortDateString();
       var teams = meet.Teams.ToArray();
       var team1 = teams[0];
       var team2 = teams[1];
       model.Team1Id = team1.Id;
       model.Team1Name = team1.Name;
       model.Team2Id = team2.Id;
       model.Team2Name = team2.Name;
       var matches = new List<MatchViewModel>();
       var early = true;
       foreach (var match in meet.Matches) {
     var matchViewModel = CreateMatchViewModel(match);
     if (early) {
       matchViewModel.TimeScheduled = "06:00 PM";
     }
     else {
       matchViewModel.TimeScheduled = "07:30 PM";
     }
     early = !early;
     matches.Add(matchViewModel);
       }
       model.Matches = matches;
       return model;
 }
コード例 #2
0
ファイル: Match.cs プロジェクト: pwideman/ClubPool
        public Match(Meet meet, MatchPlayer player1, MatchPlayer player2)
            : this()
        {
            Arg.NotNull(meet, "meet");
              Arg.NotNull(player1, "player1");
              Arg.NotNull(player2, "player2");
              Arg.Require(meet.Teams.Contains(player1.Team), "player1 is not a member of any of the meet's teams");
              Arg.Require(meet.Teams.Contains(player2.Team), "player2 is not a member of any of the meet's teams");

              Meet = meet;
              Players.Add(player1);
              player1.Match = this;
              Players.Add(player2);
              player2.Match = this;
        }
コード例 #3
0
 public MeetViewModel(Meet meet)
 {
     Id = meet.Id;
       Week = meet.Week;
       var teams = meet.Teams.ToArray();
       var team1 = teams[0];
       var team2 = teams[1];
       Team1Name = team1.Name;
       Team2Name = team2.Name;
       if (meet.IsComplete) {
     Status = MeetStatus.Complete;
       }
       else {
     if (meet.Matches.Any(m => m.IsComplete)) {
       Status = MeetStatus.Partial;
     }
     else {
       Status = MeetStatus.NotStarted;
     }
       }
 }
コード例 #4
0
 private LastMeetViewModel CreateLastMeetViewModel(Meet meet, Team team)
 {
     var model = new LastMeetViewModel();
       model.OpponentTeam = meet.Teams.Where(t => t != team).Single().Name;
       var matches = new List<LastMatchViewModel>();
       foreach (var match in meet.Matches) {
     var matchvm = CreateLastMatchViewModel(match);
     matches.Add(matchvm);
       }
       model.Matches = matches;
       return model;
 }
コード例 #5
0
ファイル: Division.cs プロジェクト: pwideman/ClubPool
        public virtual void CreateSchedule(IRepository repository, int numberOfByes = 0)
        {
            Arg.NotNull(repository, "repository");
              Arg.Require(numberOfByes >= 0, "numberOfByes must be >= 0");

              repository.Refresh(this);
              if (Meets.Any()) {
            throw new CreateScheduleException("A schedule for this division already exists");
              }
              lock (scheduleLock) {
            repository.Refresh(this);
            if (Meets.Any()) {
              throw new CreateScheduleException("A schedule for this division already exists");
            }

            var numTeams = Teams.Count;
            var realNumberOfTeams = numTeams - 1;
            if (numTeams < 2) {
              throw new ArgumentException("division must have 2 or more teams to create a schedule", "division");
            }

            var needBye = (numTeams % 2 != 0) ? true : false;
            if (0 == numberOfByes && needBye) {
              numberOfByes = 1;
            }
            numTeams += numberOfByes;
            var numWeeks = numTeams - 1;
            var opponent = -1;
            var scheduleTeams = Teams.OrderBy(t => t.SchedulePriority).ToArray();

            for (int i = 0; i < numWeeks; i++) {
              for (int j = 0; j < numTeams; j++) {
            if (j < (numTeams - 1)) {
              if (i == ((2 * j + 1) % (numTeams - 1))) {
                opponent = numTeams - 1;
              }
              else {
                opponent = ((numTeams - 1) + i - j - 1) % (numTeams - 1);
              }
            }
            else {
              for (int p = 0; p < numTeams; p++) {
                if (i == (2 * p + 1) % (numTeams - 1)) {
                  opponent = p;
                  break;
                }
              }
            }
            if (opponent != j && opponent <= realNumberOfTeams && j <= realNumberOfTeams) {
              if (!Meets.Where(m => m.Teams.Contains(scheduleTeams[j]) && m.Teams.Contains(scheduleTeams[opponent])).Any()) {
                Meet m = new Meet(scheduleTeams[j], scheduleTeams[opponent], i);
                m.CreateMatches();
                Meets.Add(m);
              }
            }
              }
            }
              }
        }
コード例 #6
0
ファイル: UserTests.cs プロジェクト: pwideman/ClubPool
        public override void EstablishContext()
        {
            player = new User("test", "test", "test", "test", "test");
              opponent = new User("opponent", "opponent", "opponent", "opponent", "opponent");
              var season = new Season("test", GameType.EightBall);
              var division = new Division("test", DateTime.Parse("1/1/2011"), season);
              playerTeam = new Team("team1", division);
              opponentTeam = new Team("team2", division);
              playerTeam.AddPlayer(player);
              opponentTeam.AddPlayer(opponent);
              meet = new Meet(playerTeam, opponentTeam, 1);

              repository = new Mock<IRepository>();
              results = new List<MatchResult>();
              repository.Setup(r => r.All<MatchResult>()).Returns(() => results.AsQueryable());
        }
コード例 #7
0
ファイル: Meets.cs プロジェクト: pwideman/ClubPool
        public override void EstablishContext()
        {
            var repository = new Mock<IRepository>();
              authenticationService = AuthHelper.CreateMockAuthenticationService();
              controller = new MeetsController(repository.Object, authenticationService);

              loggedInUser = new User("test", "test", "test", "test", "test");
              loggedInUser.SetIdTo(99);
              authenticationService.MockPrincipal.MockIdentity.IsAuthenticated = true;
              authenticationService.MockPrincipal.MockIdentity.Name = loggedInUser.Username;

              // set up a meet
              var season = new Season("s1", GameType.EightBall);
              var division = new Division("d1", DateTime.Now, season);
              var team1 = new Team("team1", division);
              team1.AddPlayer(new User("t1p1", "pass", "a", "b", "e"));
              team1.AddPlayer(new User("t1p2", "pass", "c", "d", "e"));
              var team2 = new Team("team2", division);
              team2.AddPlayer(new User("t2p1", "pass", "e", "f", "e"));
              team2.AddPlayer(new User("t2p2", "pass", "e", "f", "e"));
              meet = new Meet(team1, team2, 0);
              meet.SetIdTo(1);
              repository.Setup(r => r.Get<Meet>(meet.Id)).Returns(meet);

              var users = team1.Players.Concat(team2.Players).Concat(new List<User> { loggedInUser });
              repository.Init<User>(users.AsQueryable());
        }
コード例 #8
0
 private ScoresheetViewModel CreateScoresheetViewModel(Meet meet)
 {
     var model = new ScoresheetViewModel();
       model.Id = meet.Id;
       model.ScheduledWeek = meet.Week + 1;
       model.ScheduledDate = meet.Division.StartingDate.AddDays(meet.Week * 7);
       var teams = meet.Teams.ToArray();
       var team1 = teams[0];
       var team2 = teams[1];
       model.Team1Name = team1.Name;
       model.Team2Name = team2.Name;
       var matches = new List<ScoresheetMatchViewModel>();
       foreach (var match in meet.Matches) {
     matches.Add(CreateScoresheetMatchViewModel(match));
       }
       model.Matches = matches;
       return model;
 }
コード例 #9
0
ファイル: UpdateMatch.cs プロジェクト: pwideman/ClubPool
        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"
              };
        }