Beispiel #1
0
        public void CancelTournamentCommand_CanBeCreated_IsCreated()
        {
            CancelTournamentCommand command =
                CancelTournamentCommand.Create(TournamentTestData.GolfClubId, TournamentTestData.AggregateId, TournamentTestData.CancelTournamentRequest);

            command.ShouldNotBeNull();
            command.CommandId.ShouldNotBe(Guid.Empty);
            command.GolfClubId.ShouldBe(TournamentTestData.GolfClubId);
            command.TournamentId.ShouldBe(TournamentTestData.AggregateId);
            command.CancelTournamentRequest.ShouldNotBeNull();
            command.CancelTournamentRequest.ShouldBe(TournamentTestData.CancelTournamentRequest);
        }
        public async Task <IActionResult> PatchTournament([FromRoute] Guid golfClubId,
                                                          [FromRoute] Guid tournamentId,
                                                          TournamentPatchRequest tournamentPatchRequest,
                                                          CancellationToken cancellationToken)
        {
            // Get the Golf Club Id claim from the user
            Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId, golfClubId.ToString());

            if (tournamentPatchRequest.Status == TournamentStatusUpdate.Complete)
            {
                // Create the command
                CompleteTournamentCommand command = CompleteTournamentCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId);

                // Route the command
                await this.CommandRouter.Route(command, cancellationToken);
            }
            else if (tournamentPatchRequest.Status == TournamentStatusUpdate.Cancel)
            {
                CancelTournamentRequest cancelTournamentRequest = new CancelTournamentRequest
                {
                    CancellationReason = tournamentPatchRequest.CancellationReason
                };

                // Create the command
                CancelTournamentCommand command = CancelTournamentCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId, cancelTournamentRequest);

                // Route the command
                await this.CommandRouter.Route(command, cancellationToken);
            }
            else if (tournamentPatchRequest.Status == TournamentStatusUpdate.ProduceResult)
            {
                // Create the command
                ProduceTournamentResultCommand command = ProduceTournamentResultCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId);

                // Route the command
                await this.CommandRouter.Route(command, cancellationToken);
            }
            else
            {
                return(this.BadRequest());
            }

            // return the result
            return(this.Ok());
        }
Beispiel #3
0
        public async Task <IActionResult> Cancel([FromRoute] Guid golfClubId,
                                                 [FromRoute] Guid tournamentId,
                                                 [FromBody] CancelTournamentRequest request,
                                                 CancellationToken cancellationToken)
        {
            // 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
            CancelTournamentCommand command = CancelTournamentCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId, request);

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

            // return the result
            return(this.NoContent());
        }
 public static CancelTournamentCommand GetCancelTournamentCommand()
 {
     return(CancelTournamentCommand.Create(TournamentTestData.GolfClubId, TournamentTestData.AggregateId, TournamentTestData.CancelTournamentRequest));
 }