public async Task <IHttpActionResult> Post(
            [FromBody] MintRequest newRequest,
            [FromHeader] Guid clientRequestId,
            [RequestChecksum] string idempotencyToken,
            ODataQueryOptions <MintRequest> options,
            CancellationToken cancellationToken)
        {
            var builder = new MintBuilder().ForCatalogItem(newRequest.CatalogId)
                          .WithQuantity(newRequest.Quantity)
                          .CorrelatedBy(clientRequestId.ToString())
                          .HasIdempotencyToken(idempotencyToken);

            using (var circuitBreaker = this.NewCircuitBreaker(cancellationToken))
            {
                builder.ForBillingAccount(await accounts.FindBusinessAccount(User, circuitBreaker.Token));

                var mint = builder.NewMint();

                await bus.Send(mint, circuitBreaker.Token);

                newRequest.Id = mint.AggregateId;

                return(await circuitBreaker.CreatedOrAccepted(newRequest, ct => repository.GetSingleAsync(t => t.Id == newRequest.Id, ct)));
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> Post(
            [FromBody] Order newOrder,
            [FromHeader] Guid clientRequestId,
            [RequestChecksum] string idempotencyToken,
            ODataQueryOptions <Order> options,
            CancellationToken cancellationToken,
            bool reserveOnly = false)
        {
            var builder = new OrderBuilder().ForCatalogItem(newOrder.CatalogId)
                          .WithQuantity(newOrder.Quantity)
                          .CorrelatedBy(clientRequestId.ToString())
                          .HasIdempotencyToken(idempotencyToken);

            if (reserveOnly)
            {
                builder.ReserveTokensOnly();
            }

            using (var circuitBreaker = this.NewCircuitBreaker(cancellationToken))
            {
                builder.ForBillingAccount(await accounts.FindBusinessAccount(User, circuitBreaker.Token));

                var placeOrder = builder.NewPlaceOrder();

                await bus.Send(placeOrder, circuitBreaker.Token);

                newOrder.Id = placeOrder.AggregateId;
                newOrder.BillingAccountId = placeOrder.BillingAccountId;

                return(await circuitBreaker.CreatedOrAccepted(newOrder, ct => repository.GetSingleAsync(t => t.Id == newOrder.Id, ct)));
            }
        }
예제 #3
0
        public async Task <IHttpActionResult> Post(
            [FromBody] PrintJob newPrintJob,
            [FromHeader] Guid clientRequestId,
            [RequestChecksum] string idempotencyToken,
            ODataQueryOptions <PrintJob> options,
            CancellationToken cancellationToken)
        {
            var thumbprint = certificateLocator.LocateByAccount(User).Thumbprint;
            var builder    = new PrintJobBuilder().ForCatalogItem(newPrintJob.CatalogId)
                             .WithQuantity(newPrintJob.Quantity)
                             .WithCertificateThumbprint(thumbprint)
                             .CorrelatedBy(clientRequestId.ToString())
                             .HasIdempotencyToken(idempotencyToken);

            using (var circuitBreaker = this.NewCircuitBreaker(cancellationToken))
            {
                builder.ForBillingAccount(await accounts.FindBusinessAccount(User, circuitBreaker.Token));

                var print = builder.NewPrint();

                await bus.Send(print, circuitBreaker.Token);

                newPrintJob.Id = print.AggregateId;
                newPrintJob.BillingAccountId = print.BillingAccountId;

                return(await circuitBreaker.CreatedOrAccepted(newPrintJob, ct => repository.GetSingleAsync(t => t.Id == newPrintJob.Id, ct)));
            }
        }
예제 #4
0
        public async Task <IHttpActionResult> Activate(
            [FromODataUri] string id,
            ODataQueryOptions <Token> options,
            CancellationToken cancellationToken,
            [FromHeader] Guid?clientRequestId = null)
        {
            var expectedVersion = options.ETagValue(t => t.Version);

            using (var circuitBreaker = this.NewCircuitBreaker(cancellationToken))
            {
                var billingAccountId = await accounts.FindBusinessAccount(User, circuitBreaker.Token);

                var activate = new ActivateToken(id, expectedVersion, billingAccountId)
                {
                    CorrelationId = clientRequestId?.ToString()
                };

                await bus.Send(activate, circuitBreaker.Token);
            }

            return(Ok());
        }