public async Task HandleShipmentEventAsync(MFulfillment_ShipmentEvent eventData)
        {
            using var log = BeginFunction(nameof(FulfillmentEventMicroService), nameof(HandleShipmentEventAsync), eventData);
            try
            {
                using var ctx = CreateQuiltContext();

                switch (eventData.EventType)
                {
                case MFulfillment_ShipmentEventTypes.Process:
                {
                    var fulfillableIds = new HashSet <long>();
                    foreach (var shipmentRequestId in eventData.ShipmentRequestIds)
                    {
                        var mShipmentRequest = await FullfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId).ConfigureAwait(false);

                        foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems)
                        {
                            var mFulfillable = await FullfillmentMicroService.GetFulfillableByItemAsync(mShipmentRequestItem.FulfillableItemId).ConfigureAwait(false);

                            var fulfillableId = mFulfillable.FulfillableId;
                            if (fulfillableIds.Contains(fulfillableId))
                            {
                                _ = fulfillableIds.Add(fulfillableId);

                                if (TryParseOrderId.FromFulfillableReference(mFulfillable.FulfillableReference, out var orderId))
                                {
                                    var mOrder = await OrderMicroService.GetOrderAsync(orderId).ConfigureAwait(false);

                                    var userId = ParseUserId.FromOrdererReference(mOrder.OrdererReference);

                                    var participantReference = CreateParticipantReference.FromUserId(userId);
                                    var participantId        = await CommunicationMicroService.AllocateParticipantAsync(participantReference).ConfigureAwait(false);

                                    var topicReference = CreateTopicReference.FromOrderId(orderId);
                                    var topicId        = await CommunicationMicroService.AllocateTopicAsync(topicReference, null).ConfigureAwait(false);

                                    await CommunicationMicroService.SendNotification(participantId, NotificationTypeCodes.OrderShipped, topicId).ConfigureAwait(false);
                                }
                            }
                        }
                    }
                }
                break;
                }

                await Task.CompletedTask.ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
Пример #2
0
        public async Task <AOrder_Order> GetOrderAsync(long orderId)
        {
            using var log = BeginFunction(nameof(OrderAdminService), nameof(GetOrderAsync), orderId);
            try
            {
                await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false);

                var mOrder = await OrderMicroService.GetOrderAsync(orderId).ConfigureAwait(false);

                var mTransactions = await OrderMicroService.GetOrderTransactionSummariesAsync(orderId, null, null);

                var mEvents = await OrderMicroService.GetOrderEventLogSummariesAsync(orderId, null, null);

                var fulfillableReference = CreateFulfillableReference.FromOrderId(orderId);
                var fulfillableId        = await FulfillmentMicroService.LookupFulfillableAsync(fulfillableReference);

                var mFulfillable = fulfillableId != null
                    ? await FulfillmentMicroService.GetFulfillableAsync(fulfillableId.Value).ConfigureAwait(false)
                    : null;

                var fundableReference = CreateFundableReference.FromOrderId(orderId);
                var fundableId        = await FundingMicroService.LookupFundableAsync(fundableReference);

                var mFundable = fundableId != null
                    ? await FundingMicroService.GetFundableAsync(fundableId.Value).ConfigureAwait(false)
                    : null;

                var mUser = TryParseUserId.FromOrdererReference(mOrder.OrdererReference, out string userId)
                    ? await UserMicroService.GetUserAsync(userId)
                    : null;

                var result = Create.AOrder_Order(mOrder, mTransactions, mEvents, mFulfillable, mFundable, mUser);

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }