public async Task <IActionResult> CreateTournament([FromRoute] Guid golfClubId,
                                                           [FromBody] CreateTournamentRequest request,
                                                           CancellationToken cancellationToken)
        {
            Guid tournamentId = Guid.NewGuid();

            // Get the Golf Club Id claim from the user
            Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId, golfClubId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(golfClubId, golfClubIdClaim);

            if (validationResult == false)
            {
                return(this.Forbid());
            }

            // Create the command
            CreateTournamentCommand command = CreateTournamentCommand.Create(tournamentId, Guid.Parse(golfClubIdClaim.Value), request);

            // Route the command
            await this.CommandRouter.Route(command, cancellationToken);

            // return the result
            return(this.Created($"{TournamentController.ControllerRoute}/{tournamentId}", new CreateTournamentResponse
            {
                TournamentId = tournamentId
            }));
        }
예제 #2
0
        public void CreateTournamentCommand_CanBeCreated_IsCreated()
        {
            CreateTournamentCommand command = CreateTournamentCommand.Create(TournamentTestData.AggregateId, TournamentTestData.GolfClubId, TournamentTestData.CreateTournamentRequest);

            command.ShouldNotBeNull();
            command.CommandId.ShouldNotBe(Guid.Empty);
            command.TournamentId.ShouldBe(TournamentTestData.AggregateId);
            command.GolfClubId.ShouldBe(TournamentTestData.GolfClubId);
            command.CreateTournamentRequest.ShouldNotBeNull();
            command.CreateTournamentRequest.ShouldBe(TournamentTestData.CreateTournamentRequest);
        }
 public static CreateTournamentCommand GetCreateTournamentCommand()
 {
     return(CreateTournamentCommand.Create(TournamentTestData.AggregateId, TournamentTestData.GolfClubId, TournamentTestData.CreateTournamentRequest));
 }