Ejemplo n.º 1
0
        public async Task <string> HandleAsync(RegisterOrderCommand command, CancellationToken cancellationToken)
        {
            var transactionId = guidProvider.GenerateGuidString();

            using (var session = documentStore.OpenAsyncSession())
            {
                var transactionDocumentId = DocumentIdHelper.GetDocumentId <OrderTransaction>(documentStore, transactionId);
                var transactionDocument   = new OrderTransaction
                {
                    Id = transactionDocumentId,
                    TransactionStatus = TransactionStatus.NotStarted,
                    LoyaltyPointsConsumptionStepDetails = new StepDetails
                    {
                        Attempts         = 0,
                        RollbackAttempts = 0,
                        StepStatus       = StepStatus.NotStarted
                    },
                    DeliveryCreationStepDetails = new StepDetails
                    {
                        Attempts         = 0,
                        RollbackAttempts = 0,
                        StepStatus       = StepStatus.NotStarted
                    },
                    InventoryReservationStepDetails = new StepDetails
                    {
                        Attempts         = 0,
                        RollbackAttempts = 0,
                        StepStatus       = StepStatus.NotStarted
                    },
                    OrderTotalStepDetails = new OrderTotalStepDetails
                    {
                        Attempts         = 0,
                        RollbackAttempts = 0,
                        StepStatus       = StepStatus.NotStarted,
                        Total            = 0
                    },
                    OrderDetails = new OrderDetails
                    {
                        UserId  = command.UserId,
                        Address = AddressMapper.ToEntity(command.Address),
                        Items   = OrderMapper.ToEntities(command.Order)
                    }
                };

                await session.StoreAsync(transactionDocument, cancellationToken).ConfigureAwait(false);

                await session.SaveChangesAsync().ConfigureAwait(false);
            }

            return(transactionId);
        }