public CompetitionEntrantValidator(SameSexGameVariationValidator sameSexGameVariationValidator, MixedGameVariationValidator mixedGameVariationValidator)
        {
            this.RuleFor(x => x.Players).Custom((data, context) =>
            {
                List <CompetitionEntrant> currentEntrants = (List <CompetitionEntrant>)context.RootContextData["CurrentEntrants"];
                IEnumerable <int> result = currentEntrants.SelectMany(y => y.GetPlayerIDs());

                var newIDs = context.InstanceToValidate.GetPlayerIDs();
                bool match = newIDs.Any(playerID => result.Contains(playerID));

                if (match)
                {
                    context.AddFailure(new ValidationFailure(context.PropertyName, "A selected Player already exists in another entrant."));
                }
            });

            this.RuleFor(x => x.Players).Custom((data, context) =>
            {
                Entities.Competition competition = (Entities.Competition)context.RootContextData["Competition"];

                if (competition.GameVariation.IsMixed() && !competition.GameVariation.IsAnyCombination() && !competition.GameVariation.IsSingles())
                {
                    mixedGameVariationValidator.Validate(context);
                }
                else if (!competition.GameVariation.IsMixed())
                {
                    sameSexGameVariationValidator.Validate(context);
                }
            }
                                                );
        }
Exemplo n.º 2
0
 public static void ValidateGameFormat(ValidationResult validationResult, Entities.Competition competition, GameFormats gameFormat)
 {
     if (competition.GetEntryGameFormat() != gameFormat)
     {
         validationResult.Errors.Add(new ValidationFailure("GameFormat", "Invalid Game Format."));
     }
 }
        private async Task SaveCompetition(CreateCompetitionCommand command)
        {
            this._competition = Entities.Competition.Create(
                this._header,
                this._season,
                command.Organiser,
                command.Scope,
                command.Format,
                command.AgeGroup,
                command.Gender,
                command.AssociationID,
                command.Name,
                command.StartDate,
                command.EndDate);

            this._competition.Sponsor        = command.Sponsor;
            this._competition.OrganisingClub = this._organiserClub;
            this._competition.VenueClub      = this._venueClub;
            this._competition.GameVariation  = this._gameVariation;

            if (command.DataBit1.HasValue)
            {
                this._competition.DataBit1 = command.DataBit1;
            }

            this._competition.SetAuditFields();

            await this._competitionRepository.Save(this._competition);
        }
        public AddCompetitionEntrantCommandValidator(SinglesAddCompetitionEntrantModelValidator singlesAddCompetitionEntrantModelValidator, DoublesAddCompetitionEntrantModelValidator doublesAddCompetitionEntrantModelValidator, ThreesomesAddCompetitionEntrantModelValidator threesomesAddCompetitionEntrantModelValidator, FoursAddCompetitionEntrantModelValidator foursAddCompetitionEntrantModelValidator)
        {
            this.RuleFor(x => x.CompetitionID).NotEmpty();
            this.RuleFor(x => x.Entrant).NotEmpty().DependentRules(() =>
            {
                this.RuleFor(x => x.Entrant).Must(x => !x.HasDuplicatePlayer()).WithMessage("A player exists more than once.");
            }).DependentRules(() =>
            {
                this.RuleFor(c => c.Entrant).Custom((data, context) =>
                {
                    Entities.Competition competition = (Entities.Competition)context.RootContextData["Competition"];
                    switch (competition.GetEntryGameFormat())
                    {
                    case GameFormats.Singles:
                        singlesAddCompetitionEntrantModelValidator.Validate(context);
                        break;

                    case GameFormats.Doubles:
                        doublesAddCompetitionEntrantModelValidator.Validate(context);
                        break;

                    case GameFormats.Threesomes:
                        threesomesAddCompetitionEntrantModelValidator.Validate(context);
                        break;

                    case GameFormats.Fours:
                        foursAddCompetitionEntrantModelValidator.Validate(context);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                });
            });
        }
Exemplo n.º 5
0
        public async Task <ITeamResultEngine> GetEngine(IResultsEngineRequest request)
        {
            this._unitOfWork.GuardCheckInTransaction();

            await this._competitionRepository.GetForUpdate(request.CompetitionID);

            Entities.Competition competition = await this._competitionRepository.GetWithStages(request.CompetitionID);

            CompetitionStage stage   = this.GetStage(competition, request.CompetitionStageLoadMode, request.CompetitionStageValue);
            TeamFixture      fixture = await this._fixtureRepository.GetTeamFixtureFull(request.FixtureID);

            if (fixture.CompetitionRound.Competition.ID != competition.ID)
            {
                throw new ArgumentException("Incorrect competition/fixture ID combination", nameof(request));
            }

            ITeamFixtureModel        teamFixtureModel = this._serviceProvider.GetService <ITeamFixtureModel>();
            ITeamResultEngineContext context          = this._serviceProvider.GetService <ITeamResultEngineContext>();
            await context.Initialise(competition, stage, fixture.CompetitionRound.CompetitionEvent, fixture.CompetitionRound, teamFixtureModel);

            var engine = this._serviceProvider.GetService <ITeamResultEngine>();

            engine.SetContext(context);
            await teamFixtureModel.Initialise(fixture, context);

            return(engine);
        }
 public async Task Initialise(Entities.Competition competition, CompetitionStage stage, CompetitionEvent competitionEvent, CompetitionRound round, ITeamFixtureModel teamFixture)
 {
     this.Competition      = competition;
     this.CompetitionStage = stage;
     this.CompetitionEvent = competitionEvent;
     this.CompetitionRound = round;
     this.Fixture          = teamFixture;
 }
Exemplo n.º 7
0
 public static void Validate(ValidationResult validationResult, Entities.Competition competition)
 {
     ValidateRegistrationOnline(validationResult, competition);
     if (validationResult.IsValid)
     {
         ValidateRegistrationStatus(validationResult, competition);
     }
 }
Exemplo n.º 8
0
 public void Initialise(Entities.Competition competition, CompetitionStage stage, CompetitionEvent competitionEvent, CompetitionRound round,
                        IPlayerFixtureModel playerFixture)
 {
     this.Competition      = competition;
     this.CompetitionStage = stage;
     this.CompetitionEvent = competitionEvent;
     this.CompetitionRound = round;
     this.PlayerFixture    = playerFixture;
 }
        public virtual CompetitionEntrant CreateEntrant(Entities.Competition competition)
        {
            var data = new CompetitionEntrant();

            data.CompetitionRegistration    = this;
            data.CompetitionEntrantStatusID = CompetitionEntrantStatuses.Pending;
            data.CompetitionID       = competition.ID;
            data.EntrantGameFormatID = competition.GameVariation.GameFormatID;
            this.Entrants.Add(data);
            return(data);
        }
        public SameSexGameVariationValidator()
        {
            this.RuleFor(x => x.Players).Custom((data, context) =>
            {
                Entities.Competition competition = (Entities.Competition)context.RootContextData["Competition"];
                Genders gender = competition.GenderID;

                if (data.Any(y => y.Player.GenderID != gender))
                {
                    context.AddFailure(new ValidationFailure(context.PropertyName, $"All players must be {gender}"));
                }
            });
        }
Exemplo n.º 11
0
        private async Task Load(AddPlayerFixtureCommand command)
        {
            await this._competitionRepository.GetForUpdate(command.Competition.CompetitionID);

            this._competition = await this._competitionRepository.GetWithStages(command.Competition.CompetitionID);

            this._competitionStage = this._competition.GetStage(command.Competition.CompetitionStageLookupMode, command.Competition.CompetitionStageValue);
            this._competitionEvent = await this._competitionEventRepository.Get(command.CompetitionEventID);

            var rounds = await this._playerCompetitionRoundRepository.GetAll(this._competitionEvent.ID);

            await this.LoadRound(command, rounds);

            await this.LoadEntrants(command);

            await this.PendingFixtures(command);
        }
Exemplo n.º 12
0
        private async Task Load(UpdateOnlineRegistrationConfigurationCommand command)
        {
            await this._competitionRepository.GetForUpdate(command.CompetitionID);

            this._competition = await this._competitionRepository.GetWithRegistrationConfiguration(command.CompetitionID);

            this._association = await this._associationRepository.GetWithContacts(this._competition.AssociationID);

            if (this._competition.CompetitionOrganiserID == CompetitionOrganisers.Club)
            {
                this._club = await this._clubRepository.GetWithContacts(this._competition.OrganisingClub.ID);
            }

            if (command.OrganiserContactID.HasValue)
            {
                this._organiserContact = await this._contactRepository.Get(command.OrganiserContactID.Value);
            }
        }
Exemplo n.º 13
0
        private CompetitionStage GetStage(Entities.Competition competition, CompetitionStageLoadModes loadMode,
                                          int?optionsCompetitionStageValue)
        {
            switch (loadMode)
            {
            case CompetitionStageLoadModes.ByID:
                return(competition.GetStageByID(optionsCompetitionStageValue.Value));

                break;

            case CompetitionStageLoadModes.BySequence:
                return(competition.GetStageBySequence(optionsCompetitionStageValue.Value));

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(loadMode), loadMode, null);
            }
        }
Exemplo n.º 14
0
        public async Task <IPlayerResultEngine> GetEngine(IResultsEngineRequest request)
        {
            await this._competitionRepository.GetForUpdate(request.CompetitionID);

            Entities.Competition competition = await this._competitionRepository.GetWithStages(request.CompetitionID);

            CompetitionStage stage   = this.GetStage(competition, request.CompetitionStageLoadMode, request.CompetitionStageValue);
            PlayerFixture    fixture = await this._playerFixtureRepository.GetFull(request.FixtureID);

            IPlayerFixtureModel        playerFixtureModel = this._serviceProvider.GetService <IPlayerFixtureModel>();
            IPlayerResultEngineContext context            = this._serviceProvider.GetService <IPlayerResultEngineContext>();

            context.Initialise(competition, stage, fixture.CompetitionRound.CompetitionEvent, fixture.CompetitionRound, playerFixtureModel);

            var engine = this._serviceProvider.GetService <IPlayerResultEngine>();

            engine.SetContext(context);
            await playerFixtureModel.Initialise(fixture, context);

            return(engine);
        }
        private async Task Load(CreateDoublesRegistrationCommand command)
        {
            this._competition = await this._competitionRepository.GetForUpdate(command.Registration.CompetitionID);

            this._competition = await this._competitionRepository.GetWithRegistrationConfiguration(this._competition.ID);
        }
 public CompetitionRegistrationPlayerConfirmationEmailMessage(Entities.Competition competition, CompetitionRegistration competitionRegistration, List <CompetitionDate> dates)
 {
     this._competition             = competition;
     this._competitionRegistration = competitionRegistration;
     this._dates = dates;
 }
Exemplo n.º 17
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));
        }
Exemplo n.º 18
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);
        }
        public async Task <DefaultIdentityCommandResponse> Handle(AddCompetitionEntrantCommand command)
        {
            var status = false;
            DefaultIdentityCommandResponse response;

            this._unitOfWork.Begin();
            this._registrationUnitOfWork.Begin();

            RecaptchaResponse recaptchaResponse = null;

            try
            {
                this._competition = await this._competitionRepository.GetForUpdate(command.CompetitionID);

                this._entrants = await this._competitionEntrantRepository.GetAll(this._competition.ID);

                Dictionary <int, Common.Domain.Entities.Player> newPlayers = await this._playerRepository.GetDictionary(command.Entrant.GetPlayerIDs().ToArray());

                var validationContext = new ValidationContext <AddCompetitionEntrantCommand>(command);
                validationContext.RootContextData.Add("Competition", this._competition);

                this._validationResult = await this._addCompetitionEntrantCommandValidator.ValidateAsync(validationContext);

                if (this._validationResult.IsValid)
                {
                    var competitionEntrant = this._competition.CreateEntrant();
                    this.AddPlayer(competitionEntrant, command.Entrant.Player1, newPlayers);
                    this.AddPlayer(competitionEntrant, command.Entrant.Player2, newPlayers);
                    this.AddPlayer(competitionEntrant, command.Entrant.Player3, newPlayers);
                    this.AddPlayer(competitionEntrant, command.Entrant.Player4, newPlayers);

                    var competitionEntrantValidationContext = new ValidationContext <CompetitionEntrant>(competitionEntrant);
                    competitionEntrantValidationContext.RootContextData.Add("Competition", this._competition);
                    competitionEntrantValidationContext.RootContextData.Add("CurrentEntrants", this._entrants);
                    this._validationResult = await this._competitionEntrantValidator.ValidateAsync(competitionEntrantValidationContext);

                    if (this._validationResult.IsValid)
                    {
                        await this._competitionEntrantRepository.Save(competitionEntrant);
                    }

                    this._unitOfWork.SoftCommit();
                    this._registrationUnitOfWork.SoftCommit();

                    status   = true;
                    response = DefaultIdentityCommandResponse.Create(this._validationResult, competitionEntrant.ID);
                }
                else
                {
                    this._unitOfWork.Rollback();
                    this._registrationUnitOfWork.Rollback();
                    response = DefaultIdentityCommandResponse.Create(this._validationResult);
                }
            }
            catch (Exception e)
            {
                this._unitOfWork.Rollback();
                this._registrationUnitOfWork.Rollback();
                Console.WriteLine(e);
                throw;
            }

            return(response);
        }
        public async Task <DefaultCommandResponse> Handle(AddCompetitionEntrantResultCommand command)
        {
            var status = false;
            DefaultCommandResponse response = new DefaultCommandResponse();

            this._unitOfWork.Begin();
            this._adminUnitOfWork.Begin();

            RecaptchaResponse recaptchaResponse = null;

            try
            {
                this._competition = await this._competitionRepository.GetForUpdate(command.CompetitionID);

                this._entrants = await this._competitionEntrantRepository.GetAll(command.CompetitionID);

                var existingResults = await this._competitionEntrantResultRepository.GetAll(command.CompetitionID);

                if (existingResults.Count > 0)
                {
                    this._validationResult.Errors.Add(new ValidationFailure("ExistingResult", "There has already been a result submitted."));
                }

                if (this._validationResult.IsValid)
                {
                    this._validationResult = await this._validator.ValidateAsync(command);
                }

                if (this._validationResult.IsValid)
                {
                    foreach (var roundResult in command.Rounds)
                    {
                        var data = new CompetitionEntrantResult();
                        data.CompetitionID                    = this._competition.ID;
                        data.SeasonID                         = this._competition.Season.ID;
                        data.CompetitionName                  = this._competition.Name;
                        data.WinnerEntrant                    = this._entrants.Single(x => x.ID == roundResult.Winner.EntrantID);
                        data.LoserEntrant                     = this._entrants.Single(x => x.ID == roundResult.Loser.EntrantID);
                        data.WinnerChalks                     = roundResult.Winner.Score.Chalks;
                        data.WinnerHandicap                   = roundResult.Winner.Score.Handicap;
                        data.LoserChalks                      = roundResult.Loser.Score.Chalks;
                        data.LoserHandicap                    = roundResult.Loser.Score.Handicap;
                        data.CompetitionRoundTypeID           = roundResult.RoundTypeID;
                        data.CompetitionEntrantResultStatusID = CompetitionEntrantResultStatuses.Pending;
                        data.SetAuditFields(this._user.ID);

                        await this._competitionEntrantResultRepository.Save(data);
                    }


                    this._unitOfWork.SoftCommit();
                    this._adminUnitOfWork.SoftCommit();
                }
                else
                {
                    this._unitOfWork.Rollback();
                    this._adminUnitOfWork.Rollback();
                }

                response = DefaultCommandResponse.Create(this._validationResult);
            }
            catch (Exception e)
            {
                this._unitOfWork.Rollback();
                this._adminUnitOfWork.Rollback();
                Console.WriteLine(e);
                throw;
            }

            return(response);
        }
Exemplo n.º 21
0
        private static void ValidateRegistrationOnline(ValidationResult validationResult, Entities.Competition competition)
        {
            bool unavailable = false;

            if (competition.RegistrationConfiguration != null)
            {
                switch (competition.RegistrationConfiguration.CompetitionRegistrationModeID)
                {
                case CompetitionRegistrationModes.Unavailable:
                    unavailable = true;
                    break;

                case CompetitionRegistrationModes.Invitational:
                    validationResult.Errors.Add(new ValidationFailure("RegistrationStatus", "This competition is an invitational and cannot be entered online."));
                    break;
                }
            }
            else
            {
                unavailable = true;
            }

            if (unavailable)
            {
                validationResult.Errors.Add(new ValidationFailure("RegistrationStatus", "This competition cannot be entered online.  Please contact the club directly using the detail below."));
            }
        }
        public async Task SendSummaryEmail(List <CompetitionRegistration> registrations, Entities.Competition competition)
        {
            var dates = await this._competitionDateRepository.GetByCompetition(competition.ID);

            var message1 = new CompetitionRegistrationOrganiserSummaryEmailMessage(competition, registrations, dates);

            await this._emailSender.Send(message1);
        }
        public async Task SendConfirmationEmails(CompetitionRegistration registration, Entities.Competition competition)
        {
            var dates = await this._competitionDateRepository.GetByCompetition(competition.ID);

            var message1 = new CompetitionRegistrationPlayerConfirmationEmailMessage(competition, registration, dates);

            await this._emailSender.Send(message1);

            var message2 = new CompetitionRegistrationOrganiserConfirmationEmailMessage(competition, registration, dates);

            await this._emailSender.Send(message2);
        }
 public CompetitionRegistrationOrganiserSummaryEmailMessage(Entities.Competition competition, List <CompetitionRegistration> competitionRegistrations, List <CompetitionDate> dates)
 {
     this._competition = competition;
     this._competitionRegistrations = competitionRegistrations;
     this._dates = dates;
 }
Exemplo n.º 25
0
        private static void ValidateRegistrationStatus(ValidationResult validationResult, Entities.Competition competition)
        {
            switch (competition.GetRegistrationStatus())
            {
            case CompetitionRegistrationStatuses.Closed:
                validationResult.Errors.Add(new CompetitionRegistrationClosed(competition.RegistrationConfiguration.CloseDate.Value));
                break;

            case CompetitionRegistrationStatuses.NotOpenYet:
                validationResult.Errors.Add(new CompetitionRegistrationNotOpen(competition.RegistrationConfiguration.OpenDate.Value));
                break;
            }
        }
 private async Task Load(int competitionID)
 {
     this._competition = await this._competitionRepository.GetForUpdate(competitionID);
 }