private async Task Load(CreateCompetitionCommand command)
        {
            if (command.CompetitionHeaderID.HasValue)
            {
                this._header = await this._competitionHeaderRepository.Get(command.CompetitionHeaderID.Value);
            }

            this._season = await this._seasonRepository.Get(command.SeasonID);

            if (command.GameVariationID.HasValue)
            {
                this._gameVariation = await this._gameVariationRepository.Get(command.GameVariationID.Value);
            }

            if (command.Organiser == CompetitionOrganisers.Association)
            {
                this._venueClub = await this._clubRepository.Get(command.VenueClubID.Value);
            }

            if (command.Organiser == CompetitionOrganisers.Club)
            {
                this._organiserClub = await this._clubRepository.Get(command.OrganiserClubID.Value);

                if (command.VenueClubID.HasValue)
                {
                    this._venueClub = await this._clubRepository.Get(command.VenueClubID.Value);
                }
                else
                {
                    this._venueClub = this._organiserClub;
                }
            }
        }
Esempio n. 2
0
        public async Task <DefaultIdentityCommandResponse> Handle(CreateCompetitionHeaderCommand command)
        {
            this._unitOfWork.Begin();

            try
            {
                this._validationResult = await this._validator.ValidateAsync(command);

                if (this._validationResult.IsValid)
                {
                    var data = new CompetitionHeader
                    {
                        Name          = command.Name,
                        ShortName     = command.ShortName,
                        Priority      = command.Priority,
                        AssociationID = command.AssociationID,
                        ClubID        = command.ClubID,
                        ImportName    = command.ImportName
                    };

                    await this._competitionHeaderRepository.Save(data);

                    this._unitOfWork.SoftCommit();
                    return(DefaultIdentityCommandResponse.Create(this._validationResult, data.ID));
                }
                else
                {
                    this._unitOfWork.Rollback();
                    return(DefaultIdentityCommandResponse.Create(this._validationResult));
                }
            }
            catch (Exception e)
            {
                this._unitOfWork.Rollback();
                Console.WriteLine(e);
                throw;
            }
        }