/// <summary>
        /// Cancels the tournament.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="golfClubId">The golf club identifier.</param>
        /// <param name="tournamentId">The tournament identifier.</param>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task CancelTournament(String accessToken,
                                           Guid golfClubId,
                                           Guid tournamentId,
                                           CancelTournamentRequest request,
                                           CancellationToken cancellationToken)
        {
            String requestUri = $"{this.BaseAddress}/api/GolfClub/{golfClubId}/Tournament/{tournamentId}/Cancel";

            try
            {
                String requestSerialised = JsonConvert.SerializeObject(request);

                StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

                // Add the access token to the client headers
                this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.HttpClient.PutAsync(requestUri, httpContent, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful, no response data to deserialise
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error cancelling tournament {tournamentId}.", ex);

                throw exception;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CancelTournamentCommand" /> class.
 /// </summary>
 /// <param name="golfClubId">The golf club identifier.</param>
 /// <param name="tournamentId">The tournament identifier.</param>
 /// <param name="cancelTournamentRequest">The cancel tournament request.</param>
 /// <param name="commandId">The command identifier.</param>
 private CancelTournamentCommand(Guid golfClubId,
                                 Guid tournamentId,
                                 CancelTournamentRequest cancelTournamentRequest,
                                 Guid commandId) : base(commandId)
 {
     this.GolfClubId = golfClubId;
     this.CancelTournamentRequest = cancelTournamentRequest;
     this.TournamentId            = tournamentId;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Cancels the tournament.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="claimsIdentity">The claims identity.</param>
        /// <param name="tournamentId">The tournament identifier.</param>
        /// <param name="cancellationReason">The cancellation reason.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public async Task CancelTournament(String accessToken,
                                           ClaimsIdentity claimsIdentity,
                                           Guid tournamentId,
                                           String cancellationReason,
                                           CancellationToken cancellationToken)
        {
            CancelTournamentRequest request = new CancelTournamentRequest();

            request.CancellationReason = cancellationReason;

            Guid golfClubId = ApiClient.GetClaimValue <Guid>(claimsIdentity, "GolfClubId");

            await this.TournamentClient.CancelTournament(accessToken, golfClubId, tournamentId, request, cancellationToken);
        }
        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());
        }
        public void WhenIRequestToCancelTheTournamentNumberForGolfClubMeasuredCourseTheTournamentIsCancelled(String tournamentNumber, String golfClubNumber, String measuredCourseName)
        {
            CreateGolfClubResponse createGolfClubResponse = this.TestingContext.GetCreateGolfClubResponse(golfClubNumber);

            CreateTournamentResponse createTournamentResponse = this.TestingContext.GetCreateTournamentResponse(golfClubNumber, measuredCourseName, tournamentNumber);

            CancelTournamentRequest cancelTournamentRequest = new CancelTournamentRequest
            {
                CancellationReason = "Test Cancel"
            };

            Should.NotThrow(async() =>
            {
                await this.TestingContext.DockerHelper.GolfClubClient.CancelTournament(this.TestingContext.GolfClubAdministratorToken,
                                                                                       createGolfClubResponse.GolfClubId,
                                                                                       createTournamentResponse.TournamentId,
                                                                                       cancelTournamentRequest,
                                                                                       CancellationToken.None).ConfigureAwait(false);
            });
        }
        /// <summary>
        /// Cancels the tournament.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="golfClubId">The golf club identifier.</param>
        /// <param name="tournamentId">The tournament identifier.</param>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public async Task CancelTournament(String accessToken,
                                           Guid golfClubId,
                                           Guid tournamentId,
                                           CancelTournamentRequest request,
                                           CancellationToken cancellationToken)
        {
            String requestUri = $"{this.BaseAddress}/api/golfclubs/{golfClubId}/tournaments/{tournamentId}";

            try
            {
                // Add the access token to the client headers
                this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Create the patch request
                TournamentPatchRequest tournamentPatchRequest = new TournamentPatchRequest
                {
                    CancellationReason = request.CancellationReason,
                    Status             = TournamentStatusUpdate.Cancel
                };

                String requestSerialised = JsonConvert.SerializeObject(tournamentPatchRequest);

                StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.Patch(requestUri, httpContent, cancellationToken);

                // Process the response
                await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful there is no response object
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error cancelling tournament {tournamentId}.", ex);

                throw exception;
            }
        }
Exemplo n.º 7
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());
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates this instance.
 /// </summary>
 /// <param name="golfClubId">The golf club identifier.</param>
 /// <param name="tournamentId">The tournament identifier.</param>
 /// <param name="cancelTournamentRequest">The cancel tournament request.</param>
 /// <returns></returns>
 public static CancelTournamentCommand Create(Guid golfClubId,
                                              Guid tournamentId,
                                              CancelTournamentRequest cancelTournamentRequest)
 {
     return(new CancelTournamentCommand(golfClubId, tournamentId, cancelTournamentRequest, Guid.NewGuid()));
 }