Example #1
0
        public async Task HandleOrderEventAsync(MOrder_OrderEvent eventData)
        {
            using var log = BeginFunction(nameof(OrderEventMicroService), nameof(HandleOrderEventAsync), eventData);
            try
            {
                switch (eventData.EventTypeCode)
                {
                case OrderEventTypeCodes.FulfillmentUpdate:
                    await HandleFulfillmentRequiredEventAsync(eventData).ConfigureAwait(false);

                    break;

                case OrderEventTypeCodes.FundingUpdate:
                    await HandleFundingRequiredEventAsync(eventData).ConfigureAwait(false);

                    break;

                case OrderEventTypeCodes.Close:
                    // No action required
                    break;

                default:
                    throw new ArgumentException($"Unknown event type code {eventData.EventTypeCode}.");
                }
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
Example #2
0
        private async Task HandleFundingRequiredEventAsync(MOrder_OrderEvent eventData)
        {
            var fundableReference = CreateFundableReference.FromOrderId(eventData.OrderId);
            var fundableId        = await FundingMicroService.AllocateFundableAsync(fundableReference).ConfigureAwait(false);

            await FundingMicroService.SetFundsRequiredAsync(
                fundableId,
                eventData.FundsRequiredIncome,
                eventData.FundsRequiredSalesTax,
                eventData.FundsRequiredSalesTaxJurisdiction,
                eventData.UnitOfWork).ConfigureAwait(false);
        }
Example #3
0
        //public async Task HandleFundingEventAsync(MOrder_FundingEvent eventData)
        //{
        //    using var log = BeginFunction(nameof(OrderEventMicroService), nameof(HandleFundingEventAsync), eventData);
        //    try
        //    {
        //        await Task.CompletedTask;
        //    }
        //    catch (Exception ex)
        //    {
        //        log.LogException(ex);
        //        throw;
        //    }
        //            //}

        public async Task HandleOrderEventAsync(MOrder_OrderEvent eventData)
        {
            using var log = BeginFunction(nameof(OrderEventMicroService), nameof(HandleOrderEventAsync), eventData);
            try
            {
                await Task.CompletedTask.ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
Example #4
0
        private async Task HandleFulfillmentRequiredEventAsync(MOrder_OrderEvent eventData)
        {
            var fulfillableReference = CreateFulfillableReference.FromOrderId(eventData.OrderId);

            var existingFulfillableId = await FullfillmentMicroService.LookupFulfillableAsync(fulfillableReference);

            long fulfillableId;

            if (!existingFulfillableId.HasValue)
            {
                var allocateFulfillable = new MFulfillment_AllocateFulfillable()
                {
                    FulfillableReference = fulfillableReference,
                    Name             = $"Order {eventData.OrderNumber}",
                    ShippingAddress  = eventData.ShippingAddress,
                    FulfillableItems = new List <MFulfillment_AllocateFulfillableItem>()
                };
                foreach (var fulfillmentEventItem in eventData.OrderEventItems)
                {
                    var fulfillableItemReference = CreateFulfillableItemReference.FromOrderItemId(fulfillmentEventItem.OrderItemId);
                    var allocateFulfillableItem  = new MFulfillment_AllocateFulfillableItem()
                    {
                        FulfillableItemReference = fulfillableItemReference,
                        Description               = fulfillmentEventItem.Description,
                        ConsumableReference       = fulfillmentEventItem.ConsumableReference,
                        FulfillableItemComponents = new List <MFulfillment_AllocateFulfillableItemComponent>()
                    };
                    foreach (var fulfillmentEventItemComponent in fulfillmentEventItem.OrderEventItemComponents)
                    {
                        var allocateFulfillableItemComponent = new MFulfillment_AllocateFulfillableItemComponent()
                        {
                            Description         = fulfillmentEventItemComponent.Description,
                            ConsumableReference = fulfillmentEventItemComponent.ConsumableReference,
                            Quantity            = fulfillmentEventItemComponent.Quantity
                        };
                        allocateFulfillableItem.FulfillableItemComponents.Add(allocateFulfillableItemComponent);
                    }
                    allocateFulfillable.FulfillableItems.Add(allocateFulfillableItem);
                }

                var allocateFulfillableResponse = await FullfillmentMicroService.AllocateFulfillableAsync(allocateFulfillable);

                fulfillableId = allocateFulfillableResponse.FulfillableId;
            }
            else
            {
                fulfillableId = existingFulfillableId.Value;
            }
            //LogMessage($"Fullfillable ID = {fulfillableId}.");

            foreach (var fulfillmentEventItem in eventData.OrderEventItems)
            {
                if (fulfillmentEventItem.RequiredQuantity != 0)
                {
                    var fulfillableItemReference = CreateFulfillableItemReference.FromOrderItemId(fulfillmentEventItem.OrderItemId);
                    var fulfillableItemId        = await FullfillmentMicroService.LookupFulfillableItemAsync(fulfillableItemReference);

                    if (fulfillableItemId.HasValue)
                    {
                        await FullfillmentMicroService.SetFulfillmentRequestQuantity(fulfillableItemId.Value, fulfillmentEventItem.RequiredQuantity, eventData.UnitOfWork).ConfigureAwait(false);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Fulfillable item not found for reference {fulfillableItemReference}");
                    }
                }
            }
        }