public async Task <IActionResult> SendEmail([FromBody] SendEmailRequestDTO sendEmailRequest,
                                                    CancellationToken cancellationToken)
        {
            // Reject password tokens
            if (ClaimsHelper.IsPasswordToken(this.User))
            {
                return(this.Forbid());
            }

            Guid messageId = sendEmailRequest.MessageId.HasValue ? sendEmailRequest.MessageId.Value : Guid.NewGuid();

            // Create the command
            SendEmailRequest request = SendEmailRequest.Create(sendEmailRequest.ConnectionIdentifier,
                                                               messageId,
                                                               sendEmailRequest.FromAddress,
                                                               sendEmailRequest.ToAddresses,
                                                               sendEmailRequest.Subject,
                                                               sendEmailRequest.Body,
                                                               sendEmailRequest.IsHtml);

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

            // return the result
            return(this.Created($"{EmailController.ControllerRoute}/{messageId}",
                                new SendEmailResponseDTO
            {
                MessageId = messageId
            }));
        }
Exemple #2
0
        public async Task <IActionResult> IssueVoucher(IssueVoucherRequest issueVoucherRequest,
                                                       CancellationToken cancellationToken)
        {
            // Reject password tokens
            if (ClaimsHelper.IsPasswordToken(this.User))
            {
                return(this.Forbid());
            }

            Guid     voucherId      = Guid.NewGuid();
            DateTime issuedDateTime = issueVoucherRequest.IssuedDateTime.HasValue ? issueVoucherRequest.IssuedDateTime.Value : DateTime.Now;

            BusinessLogic.Requests.IssueVoucherRequest request = BusinessLogic.Requests.IssueVoucherRequest.Create(voucherId,
                                                                                                                   issueVoucherRequest.OperatorIdentifier,
                                                                                                                   issueVoucherRequest.EstateId,
                                                                                                                   issueVoucherRequest.TransactionId,
                                                                                                                   issuedDateTime,
                                                                                                                   issueVoucherRequest.Value,
                                                                                                                   issueVoucherRequest.RecipientEmail,
                                                                                                                   issueVoucherRequest.RecipientMobile);

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

            // TODO: Populate the GET route
            return(this.Created("", this.ModelFactory.ConvertFrom(response)));
        }
Exemple #3
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> 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 async Task <IActionResult> CreateEstateUser([FromRoute] Guid estateId,
                                                           [FromBody] CreateEstateUserRequestDTO createEstateUserRequest,
                                                           CancellationToken cancellationToken)
        {
            // Reject password tokens
            if (ClaimsHelper.IsPasswordToken(this.User))
            {
                return(this.Forbid());
            }

            // Create the command
            CreateEstateUserRequest request = CreateEstateUserRequest.Create(estateId, createEstateUserRequest.EmailAddress,
                                                                             createEstateUserRequest.Password,
                                                                             createEstateUserRequest.GivenName,
                                                                             createEstateUserRequest.MiddleName,
                                                                             createEstateUserRequest.FamilyName);

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

            // return the result
            return(this.Created($"{EstateController.ControllerRoute}/{estateId}/users/{userId}",
                                new CreateEstateUserResponse
            {
                EstateId = estateId,
                UserId = userId
            }));
        }
Exemple #6
0
        public async Task <IActionResult> SendSMS([FromBody] SendSMSRequest sendSMSRequest,
                                                  CancellationToken cancellationToken)
        {
            // Reject password tokens
            if (ClaimsHelper.IsPasswordToken(this.User))
            {
                return(this.Forbid());
            }

            Guid messageId = sendSMSRequest.MessageId.HasValue ? sendSMSRequest.MessageId.Value : Guid.NewGuid();

            // Create the command
            BusinessLogic.Requests.SendSMSRequest request = BusinessLogic.Requests.SendSMSRequest.Create(sendSMSRequest.ConnectionIdentifier,
                                                                                                         messageId,
                                                                                                         sendSMSRequest.Sender,
                                                                                                         sendSMSRequest.Destination,
                                                                                                         sendSMSRequest.Message);

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

            // return the result
            return(this.Created($"{SMSController.ControllerRoute}/{messageId}",
                                new SendSMSResponse()
            {
                MessageId = messageId
            }));
        }
Exemple #7
0
        public async Task <IActionResult> GetVoucherByCode([FromQuery] Guid estateId,
                                                           [FromQuery] String voucherCode,
                                                           CancellationToken cancellationToken)
        {
            // Reject password tokens
            if (ClaimsHelper.IsPasswordToken(this.User))
            {
                return(this.Forbid());
            }

            Voucher voucherModel = await this.VoucherManagementManager.GetVoucherByCode(estateId, voucherCode, cancellationToken);

            return(this.Ok(this.ModelFactory.ConvertFrom(voucherModel)));
        }
Exemple #8
0
        public async Task <IActionResult> RedeemVoucher(RedeemVoucherRequest redeemVoucherRequest,
                                                        CancellationToken cancellationToken)
        {
            // Reject password tokens
            if (ClaimsHelper.IsPasswordToken(this.User))
            {
                return(this.Forbid());
            }

            DateTime redeemedDateTime = redeemVoucherRequest.RedeemedDateTime.HasValue ? redeemVoucherRequest.RedeemedDateTime.Value : DateTime.Now;

            BusinessLogic.Requests.RedeemVoucherRequest request = BusinessLogic.Requests.RedeemVoucherRequest.Create(redeemVoucherRequest.EstateId, redeemVoucherRequest.VoucherCode, redeemedDateTime);

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

            return(this.Ok(this.ModelFactory.ConvertFrom(response)));
        }
        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));
        }
        public async Task <IActionResult> CreateEstate([FromBody] CreateEstateRequestDTO createEstateRequest,
                                                       CancellationToken cancellationToken)
        {
            // Reject password tokens
            if (ClaimsHelper.IsPasswordToken(this.User))
            {
                return(this.Forbid());
            }

            Guid estateId = createEstateRequest.EstateId;

            // Create the command
            CreateEstateRequest request = CreateEstateRequest.Create(estateId, createEstateRequest.EstateName);

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

            // return the result
            return(this.Created($"{EstateController.ControllerRoute}/{estateId}",
                                new CreateEstateResponse
            {
                EstateId = estateId
            }));
        }