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
            }));
        }
        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
            }));
        }
示例#3
0
        public async Task <IActionResult> GetContract([FromRoute] Guid estateId,
                                                      [FromRoute] Guid contractId,
                                                      [FromQuery] Boolean includeProducts,
                                                      [FromQuery] Boolean includeProductsWithFees,
                                                      CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Contract contract = await this.EstateManagementManager.GetContract(estateId, contractId, includeProducts, includeProductsWithFees, cancellationToken);

            if (contract == null)
            {
                throw new NotFoundException($"Contract not found with estate Id {estateId} and contract Id {contractId}");
            }

            return(this.Ok(this.ModelFactory.ConvertFrom(contract)));
        }
示例#4
0
        public async Task <IActionResult> GetPlayer([FromRoute] Guid playerId,
                                                    [FromQuery] Boolean includeMemberships,
                                                    [FromQuery] Boolean includeTournamentSignups,
                                                    CancellationToken cancellationToken)
        {
            // Get the Player Id claim from the user
            Claim playerIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.PlayerId, playerId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(playerId, playerIdClaim);

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

            GetPlayerDetailsResponse playerDetails = await this.Manager.GetPlayerDetails(Guid.Parse(playerIdClaim.Value), cancellationToken);

            List <ClubMembershipResponse> membershipList = null;

            if (includeMemberships)
            {
                membershipList = await this.Manager.GetPlayersClubMemberships(Guid.Parse(playerIdClaim.Value), cancellationToken);
            }

            PlayerSignedUpTournamentsResponse signedUpTournaments = null;

            if (includeTournamentSignups)
            {
                signedUpTournaments = await this.Manager.GetPlayerSignedUpTournaments(Guid.Parse(playerIdClaim.Value), cancellationToken);
            }

            GetPlayerResponse playerResponse = this.ConvertGetPlayerDetailsResponse(playerId, playerDetails, membershipList, signedUpTournaments);

            return(this.Ok(playerResponse));
        }
        public async Task <IActionResult> GetGolfClubList([FromQuery] Boolean includeMembers,
                                                          [FromQuery] Boolean includeMeasuredCourses,
                                                          [FromQuery] Boolean includeUsers,
                                                          [FromQuery] Boolean includeTournaments,
                                                          CancellationToken cancellationToken)
        {
            // Get the Golf Club Id claim from the user
            Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId);

            if (String.IsNullOrEmpty(golfClubIdClaim.Value) == false)
            {
                // A golf club user cannot be calling this method
                return(this.Forbid());
            }

            List <GetGolfClubResponsev1> golfClubList = await this.Manager.GetGolfClubList(cancellationToken);

            List <GetGolfClubResponsev2> response = new List <GetGolfClubResponsev2>();

            foreach (GetGolfClubResponsev1 getGolfClubResponse in golfClubList)
            {
                GetGolfClubResponsev2 getGolfClubResponsev2 = this.ConvertGetGolfClubResponse(getGolfClubResponse);
                response.Add(getGolfClubResponsev2);
            }

            return(this.Ok(response));
        }
示例#6
0
        public async Task <IActionResult> DisableTransactionFeeForProduct([FromRoute] Guid estateId,
                                                                          [FromRoute] Guid contractId,
                                                                          [FromRoute] Guid productId,
                                                                          [FromRoute] Guid transactionFeeId,
                                                                          CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            // Create the command
            DisableTransactionFeeForProductRequest command = DisableTransactionFeeForProductRequest.Create(contractId, estateId,
                                                                                                           productId,
                                                                                                           transactionFeeId);

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

            // return the result
            return(this.Ok($"{ContractController.ControllerRoute}/{contractId}/products/{productId}/transactionFees/{transactionFeeId}"));
        }
        public async Task <IActionResult> AddMeasuredCourseToGolfClub([FromRoute] Guid golfClubId,
                                                                      [FromBody] AddMeasuredCourseToClubRequest 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());
            }

            Guid golfClubIdValue  = Guid.Parse(golfClubIdClaim.Value);
            Guid measuredCourseId = Guid.NewGuid();

            // Create the command
            AddMeasuredCourseToClubCommand command = AddMeasuredCourseToClubCommand.Create(golfClubIdValue, measuredCourseId, request);

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

            // return the result
            return(this.Created($"{GolfClubController.ControllerRoute}/{golfClubId}/measuredcourses/{measuredCourseId}",
                                new AddMeasuredCourseToClubResponse
            {
                GolfClubId = golfClubIdValue,
                MeasuredCourseId = measuredCourseId
            }));
        }
示例#8
0
        public async Task <IActionResult> GetVoucher([FromQuery] String voucherCode,
                                                     [FromQuery] String applicationVersion,
                                                     CancellationToken cancellationToken)
        {
            if (ClaimsHelper.IsPasswordToken(this.User) == false)
            {
                return(this.Forbid());
            }

            // Do the software version check
            try
            {
                VersionCheckRequest versionCheckRequest = VersionCheckRequest.Create(applicationVersion);
                await this.Mediator.Send(versionCheckRequest, cancellationToken);
            }
            catch (VersionIncompatibleException vex)
            {
                Logger.LogError(vex);
                return(this.StatusCode(505));
            }

            Guid estateId   = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Value);
            Guid contractId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "contractId").Value);

            // Now do the GET
            GetVoucherRequest request = GetVoucherRequest.Create(estateId, contractId, voucherCode);

            GetVoucherResponse response = await this.Mediator.Send(request, cancellationToken);

            return(this.Ok(this.ModelFactory.ConvertFrom(response)));
        }
        public async Task <IActionResult> CreateMatchSecretary([FromRoute] Guid golfClubId,
                                                               [FromBody] CreateMatchSecretaryRequest 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());
            }

            CreateMatchSecretaryCommand command = CreateMatchSecretaryCommand.Create(Guid.Parse(golfClubIdClaim.Value), request);

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

            // return the result
            return(this.Created($"{GolfClubController.ControllerRoute}/{golfClubId}/users/{request.EmailAddress}",
                                new CreateMatchSecretaryResponse
            {
                GolfClubId = golfClubId,
                UserName = request.EmailAddress
            }));
        }
        public async Task <IActionResult> AddTournamentDivision([FromRoute] Guid golfClubId,
                                                                [FromBody] AddTournamentDivisionToGolfClubRequest 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
            AddTournamentDivisionToGolfClubCommand command = AddTournamentDivisionToGolfClubCommand.Create(Guid.Parse(golfClubIdClaim.Value), request);

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

            // return the result
            return(this.Created($"{GolfClubController.ControllerRoute}/{golfClubId}/tournamentdivisions/{request.Division}",
                                new AddTournamentDivisionToGolfClubResponse
            {
                GolfClubId = golfClubId,
                TournamentDivision = request.Division
            }));
        }
示例#11
0
        public async Task <IActionResult> AssignOperator([FromRoute] Guid estateId,
                                                         [FromRoute] Guid merchantId,
                                                         AssignOperatorRequestDTO assignOperatorRequest,
                                                         CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            AssignOperatorToMerchantRequest command = AssignOperatorToMerchantRequest.Create(estateId, merchantId, assignOperatorRequest.OperatorId,
                                                                                             assignOperatorRequest.MerchantNumber, assignOperatorRequest.TerminalNumber);

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

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}",
                                new AssignOperatorResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                OperatorId = assignOperatorRequest.OperatorId
            }));
        }
        public async Task <IActionResult> GetEstate([FromRoute] Guid estateId,
                                                    CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Estate estate = await this.EstateManagementManager.GetEstate(estateId, cancellationToken);

            if (estate == null)
            {
                throw new NotFoundException($"Estate not found with estate Id {estateId}");
            }

            return(this.Ok(this.ModelFactory.ConvertFrom(estate)));
        }
        public async Task <IActionResult> RequestClubMembership([FromRoute] Guid golfClubId,
                                                                [FromRoute] Guid playerId,
                                                                CancellationToken cancellationToken)
        {
            // Get the Player Id claim from the user
            Claim playerIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.PlayerId, playerId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(playerId, playerIdClaim);

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

            // Create the command
            RequestClubMembershipCommand command = RequestClubMembershipCommand.Create(Guid.Parse(playerIdClaim.Value), golfClubId);

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

            // return the result
            return(this.Created($"api/players/{playerId}",
                                new RequestClubMembershipResponse
            {
                GolfClubId = golfClubId,
                PlayerId = playerId,
                MembershipId = Guid.Empty
            }));
        }
示例#14
0
        public async Task <IActionResult> GetMerchant([FromRoute] Guid estateId, [FromRoute] Guid merchantId, CancellationToken cancellationToken)
        {
            String estateRoleName   = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("EstateRoleName")) ? "Estate" : Environment.GetEnvironmentVariable("EstateRoleName");
            String merchantRoleName = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MerchantRoleName")) ? "Merchant" : Environment.GetEnvironmentVariable("MerchantRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[]
            {
                estateRoleName,
                merchantRoleName
            }) == false)
            {
                return(this.Forbid());
            }

            Claim estateIdClaim   = null;
            Claim merchantIdClaim = null;

            // Determine the users role
            if (this.User.IsInRole(estateRoleName))
            {
                // Estate user
                // Get the Estate Id claim from the user
                estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId");
            }

            if (this.User.IsInRole(merchantRoleName))
            {
                // Get the merchant Id claim from the user
                estateIdClaim   = ClaimsHelper.GetUserClaim(this.User, "EstateId");
                merchantIdClaim = ClaimsHelper.GetUserClaim(this.User, "MerchantId");
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(merchantId, merchantIdClaim) == false)
            {
                return(this.Forbid());
            }

            Merchant merchant = await this.EstateManagementManager.GetMerchant(estateId, merchantId, cancellationToken);

            if (merchant == null)
            {
                throw new NotFoundException($"Merchant not found with estate Id {estateId} and merchant Id {merchantId}");
            }

            MerchantBalance merchantBalance = await this.EstateManagementManager.GetMerchantBalance(estateId, merchantId, cancellationToken);

            if (merchantBalance == null)
            {
                throw new NotFoundException($"Merchant Balance details not found with estate Id {estateId} and merchant Id {merchantId}");
            }

            return(this.Ok(this.ModelFactory.ConvertFrom(merchant, merchantBalance)));
        }
示例#15
0
        public async Task <IActionResult> MakeDeposit([FromRoute] Guid estateId,
                                                      [FromRoute] Guid merchantId,
                                                      [FromBody] MakeMerchantDepositRequestDTO makeMerchantDepositRequest,
                                                      CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            // Convert the source
            Models.MerchantDepositSource merchantDepositSourceModel = Models.MerchantDepositSource.NotSet;
            switch (makeMerchantDepositRequest.Source)
            {
            case MerchantDepositSource.Manual:
                merchantDepositSourceModel = Models.MerchantDepositSource.Manual;
                break;

            case MerchantDepositSource.Automatic:
                merchantDepositSourceModel = Models.MerchantDepositSource.Automatic;
                break;

            default:
                merchantDepositSourceModel = Models.MerchantDepositSource.Manual;
                break;
            }

            MakeMerchantDepositRequest command = MakeMerchantDepositRequest.Create(estateId,
                                                                                   merchantId,
                                                                                   merchantDepositSourceModel,
                                                                                   makeMerchantDepositRequest.Reference,
                                                                                   makeMerchantDepositRequest.DepositDateTime,
                                                                                   makeMerchantDepositRequest.Amount);

            // Route the command
            Guid depositId = await this.Mediator.Send(command, cancellationToken);

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}",
                                new MakeMerchantDepositResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                DepositId = depositId
            }));
        }
        public async Task <IActionResult> GetGolfClub([FromRoute] Guid golfClubId,
                                                      [FromQuery] Boolean includeMembers,
                                                      [FromQuery] Boolean includeMeasuredCourses,
                                                      [FromQuery] Boolean includeUsers,
                                                      [FromQuery] Boolean includeTournaments,
                                                      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());
            }

            GetGolfClubResponsev1 getGolfClubResponsev1 = await this.Manager.GetGolfClub(Guid.Parse(golfClubIdClaim.Value), cancellationToken);

            List <GetGolfClubMembershipDetailsResponse> membersList = null;

            if (includeMembers)
            {
                membersList = await this.Manager.GetGolfClubMembersList(Guid.Parse(golfClubIdClaim.Value), cancellationToken);
            }

            GetMeasuredCourseListResponse measuredCourseList = null;

            if (includeMeasuredCourses)
            {
                measuredCourseList = await this.Manager.GetMeasuredCourseList(Guid.Parse(golfClubIdClaim.Value), cancellationToken);
            }

            GetGolfClubUserListResponse users = null;

            if (includeUsers)
            {
                users = await this.Manager.GetGolfClubUsers(Guid.Parse(golfClubIdClaim.Value), cancellationToken);
            }

            GetTournamentListResponse tournamentList = null;

            if (includeTournaments)
            {
                tournamentList = await this.Manager.GetTournamentList(Guid.Parse(golfClubIdClaim.Value), cancellationToken);
            }

            GetGolfClubResponsev2 getGolfClubResponsev2 = this.ConvertGetGolfClubResponse(getGolfClubResponsev1, membersList, measuredCourseList, users, tournamentList);

            return(this.Ok(getGolfClubResponsev2));
        }
示例#17
0
        public async Task <IActionResult> GetTransactionFeesForProduct([FromRoute] Guid estateId,
                                                                       [FromRoute] Guid merchantId,
                                                                       [FromRoute] Guid contractId,
                                                                       [FromRoute] Guid productId,
                                                                       CancellationToken cancellationToken)
        {
            String estateRoleName   = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("EstateRoleName")) ? "Estate" : Environment.GetEnvironmentVariable("EstateRoleName");
            String merchantRoleName = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("MerchantRoleName")) ? "Merchant" : Environment.GetEnvironmentVariable("MerchantRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[]
            {
                estateRoleName,
                merchantRoleName
            }) == false)
            {
                return(this.Forbid());
            }

            Claim estateIdClaim   = null;
            Claim merchantIdClaim = null;

            // Determine the users role
            if (this.User.IsInRole(estateRoleName))
            {
                // Estate user
                // Get the Estate Id claim from the user
                estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId");
            }

            if (this.User.IsInRole(merchantRoleName))
            {
                // Get the merchant Id claim from the user
                estateIdClaim   = ClaimsHelper.GetUserClaim(this.User, "EstateId");
                merchantIdClaim = ClaimsHelper.GetUserClaim(this.User, "MerchantId");
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(merchantId, merchantIdClaim) == false)
            {
                return(this.Forbid());
            }

            List <TransactionFee> transactionFees = await this.EstateManagementManager.GetTransactionFeesForProduct(estateId, merchantId, contractId, productId, cancellationToken);

            return(this.Ok(this.ModelFactory.ConvertFrom(transactionFees)));
        }
示例#18
0
        public async Task <IActionResult> CreateMerchant([FromRoute] Guid estateId,
                                                         [FromBody] CreateMerchantRequestDTO createMerchantRequest,
                                                         CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Guid merchantId = Guid.NewGuid();

            // Create the command
            CreateMerchantRequest command = CreateMerchantRequest.Create(estateId,
                                                                         merchantId,
                                                                         createMerchantRequest.Name,
                                                                         createMerchantRequest.Address.AddressLine1,
                                                                         createMerchantRequest.Address.AddressLine2,
                                                                         createMerchantRequest.Address.AddressLine3,
                                                                         createMerchantRequest.Address.AddressLine4,
                                                                         createMerchantRequest.Address.Town,
                                                                         createMerchantRequest.Address.Region,
                                                                         createMerchantRequest.Address.PostalCode,
                                                                         createMerchantRequest.Address.Country,
                                                                         createMerchantRequest.Contact.ContactName,
                                                                         createMerchantRequest.Contact.PhoneNumber,
                                                                         createMerchantRequest.Contact.EmailAddress);

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

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}",
                                new CreateMerchantResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                AddressId = command.AddressId,
                ContactId = command.ContactId
            }));
        }
        public void ClaimsHelper_GetUserClaim_ClaimNotFound_DefaultReturned()
        {
            List <Claim> claims = new List <Claim>
            {
                new Claim(JwtClaimTypes.Subject, "AF821DDC-75CD-4108-8256-EAD9C62182FA"),
            };

            ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims);

            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

            Claim result = ClaimsHelper.GetUserClaim(claimsPrincipal, "testclaim", Guid.Empty.ToString());

            result.Value.ShouldBe(Guid.Empty.ToString());
        }
示例#20
0
        public async Task <IActionResult> AddTransactionFeeForProductToContract([FromRoute] Guid estateId,
                                                                                [FromRoute] Guid contractId,
                                                                                [FromRoute] Guid productId,
                                                                                [FromBody] AddTransactionFeeForProductToContractRequestDTO addTransactionFeeForProductToContractRequest,
                                                                                CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            Guid transactionFeeId = Guid.NewGuid();

            Models.Contract.CalculationType calculationType = (Models.Contract.CalculationType)addTransactionFeeForProductToContractRequest.CalculationType;
            Models.Contract.FeeType         feeType         = (Models.Contract.FeeType)addTransactionFeeForProductToContractRequest.FeeType;

            // Create the command
            AddTransactionFeeForProductToContractRequest command = AddTransactionFeeForProductToContractRequest.Create(contractId, estateId,
                                                                                                                       productId,
                                                                                                                       transactionFeeId,
                                                                                                                       addTransactionFeeForProductToContractRequest.Description,
                                                                                                                       calculationType,
                                                                                                                       feeType,
                                                                                                                       addTransactionFeeForProductToContractRequest.Value);

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

            // return the result
            return(this.Created($"{ContractController.ControllerRoute}/{contractId}/products/{productId}/transactionFees/{transactionFeeId}",
                                new AddTransactionFeeForProductToContractResponse
            {
                EstateId = estateId,
                ContractId = contractId,
                ProductId = productId,
                TransactionFeeId = transactionFeeId
            }));
        }
        public void ClaimsHelper_GetUserClaim_ClaimReturned()
        {
            List <Claim> claims = new List <Claim>
            {
                new Claim(JwtClaimTypes.Subject, "AF821DDC-75CD-4108-8256-EAD9C62182FA"),
                new Claim("testclaim", "testclaimvalue")
            };

            ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims);

            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

            Claim claim = ClaimsHelper.GetUserClaim(claimsPrincipal, "testclaim");

            claim.ShouldNotBeNull();
        }
示例#22
0
        public async Task <IActionResult> GetPlayerMemberships([FromRoute] Guid playerId, CancellationToken cancellationToken)
        {
            // Get the Player Id claim from the user
            Claim playerIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.PlayerId, playerId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(playerId, playerIdClaim);

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

            List <ClubMembershipResponse> membershipList = await this.Manager.GetPlayersClubMemberships(Guid.Parse(playerIdClaim.Value), cancellationToken);

            return(this.Ok(membershipList));
        }
        //[Authorize(Policy = PolicyNames.GetClubUsersListPolicy)]
        public async Task <IActionResult> GetUsers([FromRoute] Guid golfClubId,
                                                   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());
            }

            GetGolfClubUserListResponse users = await this.Manager.GetGolfClubUsers(Guid.Parse(golfClubIdClaim.Value), cancellationToken);

            return(this.Ok(users));
        }
        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());
        }
示例#25
0
        public async Task <IActionResult> GetPlayerTournamentSignUps([FromRoute] Guid playerId,
                                                                     CancellationToken cancellationToken)
        {
            // Get the Player Id claim from the user
            Claim playerIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.PlayerId, playerId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(playerId, playerIdClaim);

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

            PlayerSignedUpTournamentsResponse result = await this.Manager.GetPlayerSignedUpTournaments(Guid.Parse(playerIdClaim.Value), cancellationToken);

            // return the result
            return(this.Ok(result));
        }
        public async Task <IActionResult> CreateMatchSecretary([FromRoute] Guid golfClubId,
                                                               [FromBody] CreateMatchSecretaryRequest request,
                                                               CancellationToken cancellationToken)
        {
            // Get the Golf Club Id claim from the user
            Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId);

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

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

            CreateMatchSecretaryCommand command = CreateMatchSecretaryCommand.Create(Guid.Parse(golfClubIdClaim.Value), request);

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

            return(this.NoContent());
        }
示例#27
0
        public async Task <IActionResult> CreateMerchantUser([FromRoute] Guid estateId,
                                                             [FromRoute] Guid merchantId,
                                                             [FromBody] CreateMerchantUserRequestDTO createMerchantUserRequest,
                                                             CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            // Create the command
            CreateMerchantUserRequest request = CreateMerchantUserRequest.Create(estateId, merchantId, createMerchantUserRequest.EmailAddress,
                                                                                 createMerchantUserRequest.Password,
                                                                                 createMerchantUserRequest.GivenName,
                                                                                 createMerchantUserRequest.MiddleName,
                                                                                 createMerchantUserRequest.FamilyName);

            // Route the command
            Guid userId = await this.Mediator.Send(request, cancellationToken);

            // return the result
            return(this.Created($"{MerchantController.ControllerRoute}/{merchantId}/users/{userId}",
                                new CreateMerchantUserResponse
            {
                EstateId = estateId,
                MerchantId = merchantId,
                UserId = userId
            }));
        }
示例#28
0
        public async Task <IActionResult> GetContracts([FromRoute] Guid estateId,
                                                       CancellationToken cancellationToken)
        {
            // Get the Estate Id claim from the user
            Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

            String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");

            if (ClaimsHelper.IsUserRolesValid(this.User, new[] { string.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
            {
                return(this.Forbid());
            }

            if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
            {
                return(this.Forbid());
            }

            List <Contract> contracts = await this.EstateManagementManager.GetContracts(estateId, cancellationToken);

            return(this.Ok(this.ModelFactory.ConvertFrom(contracts)));
        }
        public async Task <IActionResult> AddMeasuredCourseToGolfClub([FromRoute] Guid golfClubId,
                                                                      [FromBody] AddMeasuredCourseToClubRequest 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
            AddMeasuredCourseToClubCommand command = AddMeasuredCourseToClubCommand.Create(Guid.Parse(golfClubIdClaim.Value), request.MeasuredCourseId, request);

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

            // return the result
            return(this.NoContent());
        }
        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));
        }