Exemplo n.º 1
0
        private async Task <CompetitionEntrant> CreateEntrant(CompetitionEntrant entrant, Entities.Competition competition)
        {
            List <CompetitionEntrantPlayer> players = new List <CompetitionEntrantPlayer>();

            var competitionEntrant = new CompetitionEntrant
            {
                CompetitionID       = competition.ID,
                EntrantGameFormatID = competition.GetEntryGameFormat()
            };

            foreach (var competitionEntrantPlayer in entrant.Players)
            {
                var playerEntrant = new CompetitionEntrantPlayer
                {
                    Entrant = competitionEntrant,
                    Player  = new Common.Domain.Entities.Player {
                        ID = competitionEntrantPlayer.Player.ID
                    },
                    FirstName     = competitionEntrantPlayer.FirstName,
                    LastName      = competitionEntrantPlayer.LastName,
                    CompetitionID = competition.ID
                };
                competitionEntrant.Players.Add(playerEntrant);
            }

            competitionEntrant.Confirm();

            await this._sessionProvider.Session.SaveAsync(competitionEntrant);

            return(competitionEntrant);
        }
Exemplo n.º 2
0
        public static PlayerEntrantDto AssembleDto(this CompetitionEntrant entrant)
        {
            var dto = new PlayerEntrantDto();

            dto.Players.AddRange(entrant.Players.Select(x => PlayerDtoAssembler.AssembleDto(x.Player)));
            return(dto);
        }
Exemplo n.º 3
0
        private async Task SaveGameResult(int fixtureID, CompetitionEntrant winnerEntrant, CompetitionEntrant loserEntrant, byte?winnerHandicap, byte winnerScore, byte?loserHandicap, byte loserScore, int leg = 1)
        {
            var fixture = this._playerFixtureRepository.GetFull((short)fixtureID).GetAwaiter().GetResult();
            var match   = fixture.Matches.Single(x => x.Leg == leg);
            var matchFormatXGameVariationID = match.MatchFormat.GameVariations.First().ID;
            var gameResults = this.BuildGameResult(fixtureID, matchFormatXGameVariationID, winnerEntrant, loserEntrant, winnerHandicap, winnerScore, loserHandicap, loserScore);

            await this.SaveResult(fixture.CompetitionID, fixtureID, match.ID, gameResults);
        }
Exemplo n.º 4
0
        public virtual CompetitionEntrant CreateEntrant()
        {
            var data = new CompetitionEntrant();

            data.CompetitionID = this.ID;
            data.CompetitionEntrantStatusID = CompetitionEntrantStatuses.Pending;
            data.EntrantGameFormatID        = this.GetEntryGameFormat();
            return(data);
        }
 private void AddPlayer(CompetitionEntrant competitionEntrant, AddCompetitionEntrantPlayerModel entrantPlayer, Dictionary <int, Common.Domain.Entities.Player> players)
 {
     if (entrantPlayer != null)
     {
         var player            = players[entrantPlayer.PlayerID.Value];
         var competitionPlayer = competitionEntrant.CreatePlayer(player.Forename, player.Surname);
         competitionPlayer.SetPlayer(player);
         competitionEntrant.Confirm();
     }
 }
Exemplo n.º 6
0
        public virtual void SetEntrant2(CompetitionEntrant entrant)
        {
            if (this.Entrant2 != null || this.PendingPlayer2Fixture != null)
            {
                throw new InvalidOperationException("Entrant2 or Fixture2 has already been allocated.");
            }

            this.Entrant2 = entrant;

            this.CheckFixtureReady();
        }
 public static CompetitionEntrantDto AssembleDto(this CompetitionEntrant data)
 {
     return(new CompetitionEntrantDto
     {
         ID = data.ID,
         CompetitionEntrantStatusID = data.CompetitionEntrantStatusID,
         EntrantGameFormatID = data.EntrantGameFormatID,
         Players = data.Players.Select(x => x.AssembleDto()).ToList(),
         CompetitionDateID = data.CompetitionDateID
     });
 }
        public virtual PlayerFixture CreateFixture(byte legs, CompetitionEntrant entrant1, CompetitionEntrant entrant2)
        {
            if (legs <= 0 || legs > 2)
            {
                throw new InvalidOperationException("Legs can only be one or two.");
            }

            var fixture = new PlayerFixture();

            fixture.CompetitionID              = this.Competition.ID;
            fixture.CompetitionRound           = this;
            fixture.Season                     = this.Season;
            fixture.FixtureStatusID            = FixtureStatuses.Incomplete;
            fixture.FixtureCalculationEngineID = this.CompetitionEvent.GetFixtureCalculationEngine();
            fixture.Legs = legs;
            fixture.SetAuditFields();
            fixture.Entrant1 = entrant1;
            fixture.Entrant2 = entrant2;
            this._fixtures.Add(fixture);

            return(fixture);
        }
Exemplo n.º 9
0
        private async Task LoadEntrants(AddPlayerFixtureCommand command)
        {
            if (command.Entrant1.Mode == PlayerFixtureEntrantConfigurationModel.PendingEntrantModes.Entrant)
            {
                if (command.Entrant1.EntrantID == null)
                {
                    throw new ArgumentNullException(nameof(command.Entrant1.EntrantID));
                }
                this._entrant1 = await this._competitionEntrantRepository.Get(command.Entrant1.EntrantID.Value);
            }

            if (command.Entrant2.Mode == PlayerFixtureEntrantConfigurationModel.PendingEntrantModes.Entrant)
            {
                if (command.Entrant2.EntrantID == null)
                {
                    throw new ArgumentNullException(nameof(command.Entrant2.EntrantID));
                }
                this._entrant2 = await this._competitionEntrantRepository.Get(command.Entrant2.EntrantID.Value);
            }

            if (command.Entrant1.Mode == PlayerFixtureEntrantConfigurationModel.PendingEntrantModes.Manual)
            {
                if (command.Entrant1.EntrantID == null)
                {
                    throw new ArgumentNullException(nameof(command.Entrant1.EntrantID));
                }
                this._entrant1 = await this._sessionProvider.Session.Query <CompetitionEntrant>().SingleAsync(x => x.ID == command.Entrant1.EntrantID.Value);
            }

            if (command.Entrant2.Mode == PlayerFixtureEntrantConfigurationModel.PendingEntrantModes.Manual)
            {
                if (command.Entrant2.EntrantID == null)
                {
                    throw new ArgumentNullException(nameof(command.Entrant2.EntrantID));
                }
                this._entrant2 = await this._sessionProvider.Session.Query <CompetitionEntrant>().SingleAsync(x => x.ID == command.Entrant2.EntrantID.Value);
            }
        }
Exemplo n.º 10
0
        private List <GameResult> BuildGameResult(int fixtureID, short matchFormatXGameVariationID, CompetitionEntrant winnerEntrant, CompetitionEntrant loserEntrant,
                                                  byte?winnerHandicap, byte winnerScore,
                                                  byte?loserHandicap, byte loserScore, int leg = 1)
        {
            var gameResults = new List <GameResult>();
            var result      = new GameResult();

            result.MatchFormatXGameVariationID = matchFormatXGameVariationID;
            result.HomePlayers.AddRange(winnerEntrant.Players.Select(x => x.Player.ID));
            result.AwayPlayers.AddRange(loserEntrant.Players.Select(x => x.Player.ID));
            result.HomeScore    = winnerScore;
            result.AwayScore    = loserScore;
            result.HomeHandicap = winnerHandicap;
            result.AwayHandicap = loserHandicap;
            gameResults.Add(result);
            return(gameResults);
        }
Exemplo n.º 11
0
        private async Task <DefaultIdentityCommandResponse> CreateFixture(CompetitionEntrantResult result, Entities.Competition competition, CompetitionEvent compEvent, CompetitionEntrant winnerEntrant, CompetitionEntrant loserEntrant)
        {
            var command = new AddPlayerFixtureCommand
            {
                Competition = new CompetitionLookupModel
                {
                    CompetitionID = result.CompetitionID,
                    CompetitionStageLookupMode = CompetitionLookupModel.CompetitionStageLookupModes.Auto
                },
                CompetitionEventID = compEvent.ID,
                Round = new CompetitionRoundLookupModel
                {
                    RoundType       = CompetitionRoundTypes.Final,
                    GameNumber      = 0,
                    CreateIfMissing = true
                },
                Date      = competition.StartDate,
                TotalLegs = 1,
                VenueType = VenueTypes.Neutral,
                Entrant1  = new PlayerFixtureEntrantConfigurationModel
                {
                    Mode      = PlayerFixtureEntrantConfigurationModel.PendingEntrantModes.Manual,
                    EntrantID = winnerEntrant.ID
                },
                Entrant2 = new PlayerFixtureEntrantConfigurationModel
                {
                    Mode      = PlayerFixtureEntrantConfigurationModel.PendingEntrantModes.Manual,
                    EntrantID = loserEntrant.ID
                },
                Reference = "F"
            };
            var commandHandler = this._serviceProvider.GetService <AddPlayerFixtureCommandHandler>();

            return(await commandHandler.Handle(command));
        }