public async Task <IActionResult> CreateGolfClub([FromBody] CreateGolfClubRequest request, CancellationToken cancellationToken) { if (ClaimsHelper.IsPasswordToken(this.User) == false) { return(this.Forbid()); } // Get the user id (subject) for the user Claim subjectIdClaim = ClaimsHelper.GetUserClaim(this.User, JwtClaimTypes.Subject); // Get the Golf Club Id claim from the user Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId); Guid golfClubId = Guid.Parse(golfClubIdClaim.Value); Guid securityUserId = Guid.Parse(subjectIdClaim.Value); // Create the command CreateGolfClubCommand command = CreateGolfClubCommand.Create(golfClubId, securityUserId, request); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.Created($"{GolfClubController.ControllerRoute}/{golfClubId}", new CreateGolfClubResponsev2 { GolfClubId = golfClubId })); }
public void CreateGolfClubCommand_CanBeCreated_IsCreated() { CreateGolfClubCommand command = CreateGolfClubCommand.Create(GolfClubTestData.AggregateId, GolfClubTestData.GolfClubAdministratorSecurityUserId, GolfClubTestData.CreateGolfClubRequest); command.ShouldNotBeNull(); command.CommandId.ShouldNotBe(Guid.Empty); command.GolfClubId.ShouldBe(GolfClubTestData.AggregateId); command.SecurityUserId.ShouldBe(GolfClubTestData.GolfClubAdministratorSecurityUserId); command.CreateGolfClubRequest.ShouldNotBeNull(); command.CreateGolfClubRequest.ShouldBe(GolfClubTestData.CreateGolfClubRequest); }
public async Task <IActionResult> CreateGolfClub([FromBody] CreateGolfClubRequest request, CancellationToken cancellationToken) { if (ClaimsHelper.IsPasswordToken(this.User) == false) { return(this.Forbid()); } // Get the user id (subject) for the user Claim subjectIdClaim = ClaimsHelper.GetUserClaim(this.User, JwtClaimTypes.Subject, null); // Get the Golf Club Id claim from the user Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId); // Create the command CreateGolfClubCommand command = CreateGolfClubCommand.Create(Guid.Parse(golfClubIdClaim.Value), Guid.Parse(subjectIdClaim.Value), request); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.Created($"api/golfclub/{command.Response}", command.Response)); }