コード例 #1
0
        private async Task <MFulfillment_Shipment> SetupShipment(UnitOfWork unitOfWork, int maxQuantity)
        {
            var mShipmentRequest = await SetupShipmentRequest(unitOfWork, maxQuantity);

            var mCreateShipmentItems = new List <MFulfillment_CreateShipmentItem>();

            foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems)
            {
                mCreateShipmentItems.Add(new MFulfillment_CreateShipmentItem()
                {
                    ShipmentRequestItemId = mShipmentRequestItem.ShipmentRequestItemId,
                    Quantity = mShipmentRequestItem.Quantity
                });
            }
            var mCreateShipment = new MFulfillment_CreateShipment()
            {
                ShipmentDateTimeUtc = DateTime.Today,
                TrackingCode        = "1234567890",
                ShippingVendorId    = "USPS",
                CreateShipmentItems = mCreateShipmentItems
            };
            var shipmentId = await FulfillmentMicroService.CreateShipmentAsync(mCreateShipment);

            await FulfillmentMicroService.PostShipmentAsync(shipmentId);

            await FulfillmentMicroService.ProcessShipmentAsync(shipmentId);

            var mShipment = await FulfillmentMicroService.GetShipmentAsync(shipmentId);

            return(mShipment);
        }
コード例 #2
0
        private async Task <MFulfillment_AllocateFulfillableResponse> SetupFulfillable()
        {
            var allocateFulfillable         = RandomFulfillable();
            var allocateFulfillableResponse = await FulfillmentMicroService.AllocateFulfillableAsync(allocateFulfillable);

            return(allocateFulfillableResponse);
        }
コード例 #3
0
        private async Task <MFulfillment_ReturnRequest> SetupReturnRequest(UnitOfWork unitOfWork, int quantity)
        {
            var mShipment = await SetupShipment(unitOfWork, quantity);

            var mCreateReturnRequestItems = new List <MFulfillment_CreateReturnRequestItem>();

            foreach (var mShipmentItem in mShipment.ShipmentItems)
            {
                mCreateReturnRequestItems.Add(new MFulfillment_CreateReturnRequestItem()
                {
                    FulfillableItemId = mShipmentItem.FulfillableItemId,
                    Quantity          = mShipmentItem.Quantity
                });
            }
            var mCreateReturnRequest = new MFulfillment_CreateReturnRequest()
            {
                ReturnRequestType       = MFulfillment_ReturnRequestTypes.Return,
                ReturnRequestReasonCode = "ITEM-DEFECTIVE",
                Notes = "Notes",
                CreateReturnRequestItems = mCreateReturnRequestItems
            };
            var returnRequestId = await FulfillmentMicroService.CreateReturnRequestAsync(mCreateReturnRequest);

            await FulfillmentMicroService.PostReturnRequestAsync(returnRequestId);

            var mReturnRequest = await FulfillmentMicroService.GetReturnRequestAsync(returnRequestId);

            return(mReturnRequest);
        }
コード例 #4
0
        public async Task <AEvent_EventLogList> GetEventLogsAsync(string unitOfWork, string source)
        {
            using var log = BeginFunction(nameof(EventAdminService), nameof(GetEventLogsAsync), unitOfWork);
            try
            {
                await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false);

                var eventLogs = new AEvent_EventLogList()
                {
                    MFunderEventLogs          = await FundingMicroService.GetFunderEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MFundableEventLogs        = await FundingMicroService.GetFundableEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MFulfillableEventLogs     = await FulfillmentMicroService.GetFulfillableEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MShipmentRequestEventLogs = await FulfillmentMicroService.GetShipmentRequestEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MShipmentEventLogs        = await FulfillmentMicroService.GetShipmentEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MReturnRequestTrnsactions = await FulfillmentMicroService.GetReturnRequestEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MReturnEventLogs          = await FulfillmentMicroService.GetReturnEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MOrderEventLogs           = await OrderMicroService.GetOrderEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MSquarePaymentEventLogs   = await SquareMicroService.GetPaymentEventLogSummariesAsync(null, unitOfWork, source).ConfigureAwait(false),
                    MSquareRefundEventLogs    = await SquareMicroService.GetRefundEventLogSummariesAsync(null, null, unitOfWork, source).ConfigureAwait(false)
                };

                var result = eventLogs;

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
コード例 #5
0
        public async Task <int> ProcessPendingEvents()
        {
            using var log = BeginFunction(nameof(EventProcessorMicroService), nameof(ProcessPendingEvents));
            try
            {
                var totalCount = 0;

                int iterationCount;
                do
                {
                    iterationCount  = 0;
                    iterationCount += await CommunicationMicroService.ProcessEventsAsync();

                    iterationCount += await FulfillmentMicroService.ProcessEventsAsync();

                    iterationCount += await FundingMicroService.ProcessEventsAsync();

                    iterationCount += await InventoryMicroService.ProcessEventsAsync();

                    iterationCount += await OrderMicroService.ProcessEventsAsync();

                    iterationCount += await SquareMicroService.ProcessEventsAsync();

                    iterationCount += await UserMicroService.ProcessEventsAsync();

                    //Task<int>[] tasks = {
                    //CommunicationMicroService.ProcessEventsAsync(),
                    //FulfillmentMicroService.ProcessEventsAsync(),
                    //FundingMicroService.ProcessEventsAsync(),
                    //InventoryMicroService.ProcessEventsAsync(),
                    //OrderMicroService.ProcessEventsAsync(),
                    //PayPalMicroService.ProcessEventsAsync(),
                    //SquareMicroService.ProcessEventsAsync(),
                    //UserMicroService.ProcessEventsAsync() };
                    //var counts = await Task.WhenAll(tasks);
                    //iterationCount = counts.Sum();

                    totalCount += iterationCount;
                } while (iterationCount > 0);

                var result = totalCount;

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
コード例 #6
0
        public async Task CreateShipment()
        {
            var logger = ServiceScope.ServiceProvider.GetService <ILogger <FulfillmentTest> >();

            var unitOfWork  = CreateUnitOfWork.Timestamp(GetUniqueNow());
            int maxQuantity = 10;

            var mShipmentRequest = await SetupShipmentRequest(unitOfWork, maxQuantity);

            var mCreateShipmentItems = new List <MFulfillment_CreateShipmentItem>();

            foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems)
            {
                mCreateShipmentItems.Add(new MFulfillment_CreateShipmentItem()
                {
                    ShipmentRequestItemId = mShipmentRequestItem.ShipmentRequestItemId,
                    Quantity = mShipmentRequestItem.Quantity
                });
            }
            var mCreateShipment = new MFulfillment_CreateShipment()
            {
                ShipmentDateTimeUtc = DateTime.Today,
                TrackingCode        = "1234567890",
                ShippingVendorId    = "USPS",
                CreateShipmentItems = mCreateShipmentItems
            };
            var shipmentId = await FulfillmentMicroService.CreateShipmentAsync(mCreateShipment);

            logger.LogInformation($"Shipment {shipmentId} created.");

            var eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            await FulfillmentMicroService.PostShipmentAsync(shipmentId);

            logger.LogInformation($"Shipment {shipmentId} posted.");

            eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            await FulfillmentMicroService.ProcessShipmentAsync(shipmentId);

            logger.LogInformation($"Shipment {shipmentId} processed.");

            eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");
        }
コード例 #7
0
        public async Task UpdateShipmentAsync(AShipment_UpdateShipment updateShipment)
        {
            using var log = BeginFunction(nameof(ShipmentAdminService), nameof(UpdateShipmentAsync), updateShipment);
            try
            {
                await Assert(SecurityPolicy.AllowEditFulfillment);

                await FulfillmentMicroService.UpdateShipmentAsync(updateShipment.MUpdateShipment);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
コード例 #8
0
        public async Task PostShipmentAsync(long shipmentId)
        {
            using var log = BeginFunction(nameof(ShipmentAdminService), nameof(PostShipmentAsync), shipmentId);
            try
            {
                await Assert(SecurityPolicy.AllowEditFulfillment);

                await FulfillmentMicroService.PostShipmentAsync(shipmentId);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
コード例 #9
0
        public async Task CancelShipmentAsync(long shipmentId)
        {
            using var log = BeginFunction(nameof(ShipmentAdminService), nameof(CancelShipmentAsync), shipmentId);
            try
            {
                await Assert(SecurityPolicy.AllowEditFulfillment);

                await FulfillmentMicroService.CancelShipmentAsync(shipmentId);

                _ = await EventProcessorMicroService.ProcessPendingEvents().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
コード例 #10
0
        public async Task CreateReturn()
        {
            var logger = ServiceScope.ServiceProvider.GetService <ILogger <FulfillmentTest> >();

            var unitOfWork  = CreateUnitOfWork.Timestamp(GetUniqueNow());
            int maxQuantity = 10;

            var mReturnRequest = await SetupReturnRequest(unitOfWork, maxQuantity);

            var mCreateReturn = new MFulfillment_CreateReturn()
            {
                CreateDateTimeUtc = DateTime.Now,
                CreateReturnItems = mReturnRequest.ReturnRequestItems
                                    .Select(r => new MFulfillment_CreateReturnItem()
                {
                    ReturnRequestItemId = r.ReturnRequestItemId,
                    Quantity            = r.Quantity
                }).ToList()
            };
            var returnId = await FulfillmentMicroService.CreateReturnAsync(mCreateReturn);

            logger.LogInformation($"Return {returnId} created.");

            var eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            await FulfillmentMicroService.PostReturnAsync(returnId);

            logger.LogInformation($"Return {returnId} posted.");

            eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            await FulfillmentMicroService.ProcessReturnAsync(returnId);

            logger.LogInformation($"Return {returnId} processed.");

            eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");
        }
コード例 #11
0
        public async Task <AShipment_ShipmentRequest> GetShipmentRequestAsync(long shipmentRequestId)
        {
            using var log = BeginFunction(nameof(ShipmentAdminService), nameof(GetShipmentRequestAsync), shipmentRequestId);
            try
            {
                await Assert(SecurityPolicy.AllowViewFulfillment);

                var mShipmentRequest = await FulfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId);

                var mTransactions = await FulfillmentMicroService.GetShipmentRequestTransactionSummariesAsync(shipmentRequestId, null, null);

                var mEvents = await FulfillmentMicroService.GetShipmentRequestEventLogSummariesAsync(shipmentRequestId, null, null);

                var mFulfillables = new List <MFulfillment_Fulfillable>();
                foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems)
                {
                    // Retrieve the associated fulfillable if we haven't already.
                    //
                    var fulfillableId = mShipmentRequestItem.FulfillableId;
                    if (!mFulfillables.Any(r => r.FulfillableId == fulfillableId))
                    {
                        var mFulfillable = await FulfillmentMicroService.GetFulfillableAsync(fulfillableId).ConfigureAwait(false);

                        mFulfillables.Add(mFulfillable);
                    }
                }

                var allowEdit = await SecurityPolicy.AllowEditFulfillment();

                var shipmentRequest = Create.AShipment_ShipmentRequest(mShipmentRequest, mTransactions, mEvents, mFulfillables, allowEdit);

                var result = shipmentRequest;

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
コード例 #12
0
        public async Task CreateReturnRequest()
        {
            var logger = ServiceScope.ServiceProvider.GetService <ILogger <FulfillmentTest> >();

            var unitOfWork  = CreateUnitOfWork.Timestamp(GetUniqueNow());
            int maxQuantity = 10;

            var mShipment = await SetupShipment(unitOfWork, maxQuantity);

            var mCreateReturnRequestItems = new List <MFulfillment_CreateReturnRequestItem>();

            foreach (var mShipmentItem in mShipment.ShipmentItems)
            {
                mCreateReturnRequestItems.Add(new MFulfillment_CreateReturnRequestItem()
                {
                    FulfillableItemId = mShipmentItem.FulfillableItemId,
                    Quantity          = mShipmentItem.Quantity
                });
            }
            var mCreateReturnRequest = new MFulfillment_CreateReturnRequest()
            {
                ReturnRequestType       = MFulfillment_ReturnRequestTypes.Return,
                ReturnRequestReasonCode = "ITEM-DEFECTIVE",
                Notes = "Notes",
                CreateReturnRequestItems = mCreateReturnRequestItems
            };

            var returnRequestId = await FulfillmentMicroService.CreateReturnRequestAsync(mCreateReturnRequest);

            logger.LogInformation($"Return request {returnRequestId} created.");

            var eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            await FulfillmentMicroService.PostReturnRequestAsync(returnRequestId);

            logger.LogInformation($"Return request {returnRequestId} posted.");

            eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");
        }
コード例 #13
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;
            }
        }
コード例 #14
0
        public async Task <ActionResult> ReturnConfirm(ReturnRequestEditModel model)
        {
            var actionData = this.GetActionData();

            switch (actionData?.ActionName)
            {
            case Actions.Continue:
            {
                await FulfillmentMicroService.PostReturnRequestAsync(model.OrderReturnRequestId.Value);

                return(RedirectToAction("ReturnComplete", new { id = model.OrderId }));
            }

            case Actions.Back:
            {
                return(RedirectToAction("ReturnEditItems", new { id = model.OrderId }));
            }
            }

            return(View());
        }
コード例 #15
0
        public async Task <long> CreateShipmentAsync(AShipment_CreateShipment createShipment)
        {
            using var log = BeginFunction(nameof(ShipmentAdminService), nameof(CreateShipmentAsync), createShipment);
            try
            {
                await Assert(SecurityPolicy.AllowEditFulfillment);

                var shipmentId = await FulfillmentMicroService.CreateShipmentAsync(createShipment.MCreateShipment);

                var result = shipmentId;

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
コード例 #16
0
        public async Task CreateFulfillable()
        {
            var logger     = ServiceScope.ServiceProvider.GetService <ILogger <FulfillmentTest> >();
            var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow());

            var allocateFulfillableResponse = await FulfillmentMicroService.AllocateFulfillableAsync(RandomFulfillable());

            var fulfillableId = allocateFulfillableResponse.FulfillableId;

            logger.LogInformation($"Fulfillable ID = {fulfillableId}");
            foreach (var allowcateFulfillableItemResponse in allocateFulfillableResponse.FulfillableItemResponses)
            {
                var fulfillableItemId = allowcateFulfillableItemResponse.FulfillableItemId;
                logger.LogInformation($"Fulfillable Item ID = {fulfillableItemId}");
            }

            var eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            foreach (var allowcateFulfillableItemResponse in allocateFulfillableResponse.FulfillableItemResponses)
            {
                var quantity          = Random.Next(9) + 1;
                var fulfillableItemId = allowcateFulfillableItemResponse.FulfillableItemId;
                logger.LogInformation($"Fulfillable Item ID = {fulfillableItemId}");
                await FulfillmentMicroService.SetFulfillmentRequestQuantity(fulfillableItemId, quantity, unitOfWork.Next());

                logger.LogInformation($"Fulfillment item {fulfillableItemId} required quantity updated to {quantity}.");
            }

            eventCount = await EventProcessorMicroService.ProcessPendingEvents();

            logger.LogInformation($"{eventCount} events processed.");

            var mShipmentRequestSummaryList = await FulfillmentMicroService.GetShipmentRequestSummariesAsync(MFulfillment_ShipmentRequestStatus.Pending, null);

            Assert.IsTrue(mShipmentRequestSummaryList.Summaries.Any(r => r.FulfillableId == fulfillableId));
        }
コード例 #17
0
        private async Task <MFulfillment_ShipmentRequest> SetupShipmentRequest(UnitOfWork unitOfWork, int maxQuantity)
        {
            //var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow());

            //var utcNow = DateTime.UtcNow;
            //var name = $"Fulfillable {utcNow.Year - 2000:00}-{utcNow.DayOfYear:000}-{utcNow.Hour * utcNow.Minute:0000}.{utcNow.Millisecond:000}";

            var allocateFulfillableResponse = await SetupFulfillable();

            foreach (var fulfillableItem in allocateFulfillableResponse.FulfillableItemResponses)
            {
                int quantity = Random.Next(maxQuantity) + 1;
                await FulfillmentMicroService.SetFulfillmentRequestQuantity(fulfillableItem.FulfillableItemId, quantity, unitOfWork.Next());
            }

            var shipmentRequestId = await FulfillmentMicroService.GetPendingShipmentRequestAsync(allocateFulfillableResponse.FulfillableId);

            await FulfillmentMicroService.OpenShipmentRequestAsync(shipmentRequestId.Value);

            var mShipmentRequest = await FulfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId.Value);

            return(mShipmentRequest);
        }
コード例 #18
0
        public async Task <IReadOnlyList <AShipment_ShipmentRequestSummary> > GetShipmentRequestSummariesAsync(MFulfillment_ShipmentRequestStatus shipmentRequestStatus, int?recordCount)
        {
            using var log = BeginFunction(nameof(ShipmentAdminService), nameof(GetShipmentRequestSummariesAsync), shipmentRequestStatus, recordCount);
            try
            {
                await Assert(SecurityPolicy.AllowViewFulfillment);

                var mShipmentRequestSummaryList = await FulfillmentMicroService.GetShipmentRequestSummariesAsync(shipmentRequestStatus, recordCount).ConfigureAwait(false);

                var summaries = Create.AShipment_ShipmentRequestSummaries(mShipmentRequestSummaryList.Summaries);

                var result = summaries;

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
コード例 #19
0
        public async Task <ActionResult> Index(long id)
        {
            var svcOrder = await OrderUserService.GetOrderAsync(id);

            var model = ModelFactory.CreateReturnRequestViewModel(svcOrder, null, await FulfillmentMicroService.GetReturnRequestReasonsAsync());

            return(View("ReturnStart", model));
        }
コード例 #20
0
        public async Task <ActionResult> ReturnEditItems(ReturnRequestEditModel model)
        {
            if (ModelState.IsValid)
            {
                var quantitySpecified = false;// Assume failure.
                foreach (var item in model.Items)
                {
                    if (item.Quantity > 0)
                    {
                        quantitySpecified = true;
                        break;
                    }
                }
                if (!quantitySpecified)
                {
                    ModelState.AddModelError("", "No items have been selected.");
                }
            }
            if (!ModelState.IsValid)
            {
                var svcOrder = await OrderUserService.GetOrderAsync(model.OrderId);

                var svcReturnRequest = GetActiveReturnRequest(svcOrder);

                model = ModelFactory.CreateReturnRequestEditModel(svcOrder, svcReturnRequest, await FulfillmentMicroService.GetReturnRequestReasonsAsync());

                return(View(model));
            }

            var actionData = this.GetActionData();

            switch (actionData?.ActionName)
            {
            case Actions.Continue:
            {
                //if (svcReturnRequest.ReturnRequestId.HasValue)
                //{
                //    var svcReturnRequest = await CreateReturnRequestAsync(model);

                //    await FulfillmentMicroService.UpdateReturnRequestAsync(svcReturnRequest);
                //}
                //else
                //{
                //    var svcReturnRequest = await CreateReturnRequestAsync(model);

                //    _ = await FulfillmentMicroService.CreateReturnRequestAsync(svcReturnRequest);
                //}

                return(RedirectToAction("ReturnConfirm", new { id = model.OrderId }));
            }

            case Actions.Back:
            {
                return(RedirectToAction("Index", new { id = model.OrderId }));
            }
            }

            return(View());
        }
コード例 #21
0
ファイル: OrderTest.cs プロジェクト: rgtodd/quiltsystem
        public async Task CreateAndShipOrder()
        {
            var services = ServiceScope.ServiceProvider;
            var logger   = services.GetService <ILogger <OrderTest> >();

            var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow());

            // Get the user ID.
            //
            string userId;
            {
                var identityUser = await UserManager.FindByNameAsync("*****@*****.**");

                userId = identityUser.Id;
                logger.LogInformation("User ID = {0}", userId);
            }

            // Get the orderer ID.
            //
            long ordererId;
            {
                var ordererReference = CreateOrdererReference.FromTimestamp(GetUniqueNow());
                ordererId = await OrderMicroService.AllocateOrdererAsync(ordererReference);

                logger.LogInformation("Orderer ID = {0}", ordererId);
            }

            // Get the funder ID.
            //
            long funderId;
            {
                var funderReference = CreateFunderReference.FromTimestamp(GetUniqueNow());
                funderId = await FundingMicroService.AllocateFunderAsync(funderReference);

                logger.LogInformation("Funder ID = {0}", funderId);
            }

            // Create the design.
            //
            Guid designId;
            {
                var designData = Factory.CreateDesign();
                designId = await DesignAjaxService.SaveDesignAsync(userId, designData);

                logger.LogInformation($"Design ID = {designId}");
            }

            // Create the project.
            //
            string projectId;
            {
                projectId = await ProjectUserService.CreateProjectAsync(userId, ProjectUserService.ProjectType_Kit, "Test Project", designId);

                logger.LogInformation($"Project ID = {projectId}");
            }

            // Create the orderable ID.
            //
            long orderableId;
            {
                var projectSnapshotId = await ProjectMicroService.GetCurrentSnapshotIdAsync(Guid.Parse(projectId));

                var mProjectSnapshotDetail = await ProjectMicroService.GetProjectSnapshotAsync(projectSnapshotId);

                var mAllocateOrderable             = MicroDataFactory.MOrder_AllocateOrderable(mProjectSnapshotDetail);
                var mAllocateOrderableResponseData = await OrderMicroService.AllocateOrderableAsync(mAllocateOrderable);

                orderableId = mAllocateOrderableResponseData.OrderableId;
                logger.LogInformation($"Orderable ID = {orderableId}");
            }

            var shippingAddress = new MCommon_Address()
            {
                Name         = "RICH TODD",
                AddressLine1 = "17340 W 156 TER",
                City         = "OLATHE",
                StateCode    = "KS",
                PostalCode   = "66062",
                CountryCode  = "US"
            };

            // Create the order.
            //
            long orderId;

            {
                // Add item to cart.
                //
                _ = await OrderMicroService.AddCartItemAsync(ordererId, orderableId, 2);

                // Update shipping address.
                //
                _ = await OrderMicroService.UpdateShippingAddressAsync(ordererId, shippingAddress);

                // Submit order.
                //
                orderId = await OrderMicroService.SubmitCartAsync(ordererId);

                logger.LogInformation($"Order ID = {orderId}");
            }

            _ = await EventProcessorMicroService.ProcessPendingEvents();

            // Create fundable for order.
            //
            long fundableId;
            {
                var fundableReference = CreateFundableReference.FromOrderId(orderId);
                fundableId = await FundingMicroService.AllocateFundableAsync(fundableReference);

                logger.LogInformation($"Fundable ID = {fundableId}");
            }

            // Retrieve the fundable detail.
            //
            MFunding_Fundable fundableDetail;

            {
                fundableDetail = await FundingMicroService.GetFundableAsync(fundableId);

                logger.LogInformation($"Fundable Detail = {fundableDetail}");
            }

            // Post a receipt for the order.
            //
            {
                var fundsRequiredDelta = fundableDetail.FundsRequiredTotal - fundableDetail.FundsReceived;
                await FundingMicroService.SetFundsReceivedAsync(funderId, fundableDetail.FundableReference, fundableDetail.FundsRequiredTotal, unitOfWork.Next());

                //await fundingService.TransferFundsAsync(funderId, fundableId, fundsRequiredDelta);
                logger.LogInformation($"{fundsRequiredDelta} funds applied.");
            }

            _ = await EventProcessorMicroService.ProcessPendingEvents();

            // Lookup fulfillable.
            //
            long fulfillableId;
            {
                var fulfillableReference = CreateFulfillableReference.FromOrderId(orderId);
                fulfillableId = (await FulfillmentMicroService.LookupFulfillableAsync(fulfillableReference)).Value;
                await FulfillmentMicroService.SetFulfillableShippingAddress(fulfillableId, shippingAddress);

                logger.LogInformation($"Fulfillable ID = {fulfillableId}");
            }

            // Lookup pending shipment request.
            //
            long?shipmentRequestId;
            {
                shipmentRequestId = await FulfillmentMicroService.GetPendingShipmentRequestAsync(fulfillableId);

                logger.LogInformation($"Shipment Request ID = {shipmentRequestId}");
            }

            // Open it.
            //
            {
                await FulfillmentMicroService.OpenShipmentRequestAsync(shipmentRequestId.Value);
            }

            // Lookup shipment request.
            //
            MFulfillment_ShipmentRequest shipmentRequestDetail;
            {
                shipmentRequestDetail = await FulfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId.Value);

                logger.LogInformation($"Shipment Request Detail = {shipmentRequestDetail}");
            }

            // Create shipment.
            //
            long shipmentId;

            {
                var items = new List <MFulfillment_CreateShipmentItem>();
                foreach (var shipmentRequestItemDetail in shipmentRequestDetail.ShipmentRequestItems)
                {
                    items.Add(new MFulfillment_CreateShipmentItem()
                    {
                        ShipmentRequestItemId = shipmentRequestItemDetail.ShipmentRequestItemId,
                        Quantity = shipmentRequestItemDetail.Quantity
                    });
                }

                var data = new MFulfillment_CreateShipment()
                {
                    ShippingVendorId    = ShippingVendorIds.Usps,
                    ShipmentDateTimeUtc = Locale.GetUtcNow(),
                    TrackingCode        = "123123",
                    CreateShipmentItems = items
                };

                shipmentId = await FulfillmentMicroService.CreateShipmentAsync(data);

                await FulfillmentMicroService.PostShipmentAsync(shipmentId);

                await FulfillmentMicroService.ProcessShipmentAsync(shipmentId);

                logger.LogInformation($"Shipment ID = {shipmentId}");
            }

            _ = await EventProcessorMicroService.ProcessPendingEvents();
        }
コード例 #22
0
        public async Task <ActionResult> ReturnConfirm(long id)
        {
            var svcOrder = await OrderUserService.GetOrderAsync(id);

            var svcReturnRequest = GetActiveReturnRequest(svcOrder);

            var model = ModelFactory.CreateReturnRequestViewModel(svcOrder, svcReturnRequest, await FulfillmentMicroService.GetReturnRequestReasonsAsync());

            return(View(model));
        }
コード例 #23
0
        public async Task <ADashboard_Summary> GetDashboardDataAsync()
        {
            using var log = BeginFunction(nameof(DashboardAdminService), nameof(GetDashboardDataAsync));
            try
            {
                await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false);

                var result = new ADashboard_Summary()
                {
                    MCommunication_Dashboard = await CommunicationMicroService.GetDashboardAsync(),
                    MDesign_Dashboard        = await DesignMicroService.GetDashboardAsync(),
                    MFulfillment_Dashboard   = await FulfillmentMicroService.GetDashboardAsync(),
                    MFunding_Dashboard       = await FundingMicroService.GetDashboardAsync(),
                    MLedger_Dashboard        = await LedgerMicroService.GetDashboardAsync(),
                    MOrder_Dashboard         = await OrderMicroService.GetDashboardAsync(),
                    MProject_Dashboard       = await ProjectMicroService.GetDashboardAsync(),
                    MSquare_Dashboard        = await SquareMicroService.GetDashboardAsync(),
                    MUser_Dashboard          = await UserMicroService.GetDashboardAsync()
                };

                //using (var ctx = QuiltContextFactory.Create())
                //{
                //    using var conn = QuiltContextFactory.CreateConnection();

                //    conn.Open();

                //    // Order
                //    //
                //    {
                //        var statusCounts = new List<Admin_Dashboard_StatusCountData>();
                //        foreach (var dbOrder in GetDashboardOrders(conn).ToList())
                //        {
                //            var statusCount = new Admin_Dashboard_StatusCountData()
                //            {
                //                StatusName = ctx.OrderStatusType(dbOrder.OrderStatusTypeCode).Name,
                //                Count = dbOrder.RecordCount.GetValueOrDefault()
                //            };
                //            statusCounts.Add(statusCount);
                //        }
                //        result.OrderStatusCounts = statusCounts;
                //    }

                //    // Order Return Request
                //    //
                //    {
                //        var statusCounts = new List<Admin_Dashboard_StatusCountData>();
                //        foreach (var dbOrderReturnRequest in GetDashboardOrderReturnRequests(conn).ToList())
                //        {
                //            var statusCount = new Admin_Dashboard_StatusCountData()
                //            {
                //                StatusName = ctx.ReturnRequestStatusType(dbOrderReturnRequest.OrderReturnRequestStatusTypeCode).Name,
                //                Count = dbOrderReturnRequest.RecordCount.GetValueOrDefault()
                //            };
                //            statusCounts.Add(statusCount);
                //        }
                //        result.OrderReturnRequestStatusCounts = statusCounts;
                //    }

                //    // Order Return
                //    //
                //    {
                //        var statusCounts = new List<Admin_Dashboard_StatusCountData>();
                //        foreach (var dbOrderReturn in GetDashboardOrderReturns(conn).ToList())
                //        {
                //            var statusCount = new Admin_Dashboard_StatusCountData()
                //            {
                //                StatusName = ctx.ReturnStatusType(dbOrderReturn.OrderReturnStatusTypeCode).Name,
                //                Count = dbOrderReturn.RecordCount.GetValueOrDefault()
                //            };
                //            statusCounts.Add(statusCount);
                //        }
                //        result.OrderReturnStatusCounts = statusCounts;
                //    }

                //    // Order Shipment Request
                //    //
                //    {
                //        var statusCounts = new List<Admin_Dashboard_StatusCountData>();
                //        foreach (var dbOrderShipmentRequest in GetDashboardOrderShipmentRequests(conn).ToList())
                //        {
                //            var statusCount = new Admin_Dashboard_StatusCountData()
                //            {
                //                StatusName = ctx.ShipmentRequestStatusType(dbOrderShipmentRequest.OrderShipmentRequestStatusTypeCode).Name,
                //                Count = dbOrderShipmentRequest.RecordCount.GetValueOrDefault()
                //            };
                //            statusCounts.Add(statusCount);
                //        }
                //        result.OrderShipmentRequestStatusCounts = statusCounts;
                //    }

                //    // Order Shipment
                //    //
                //    {
                //        var statusCounts = new List<Admin_Dashboard_StatusCountData>();
                //        foreach (var dbOrderShipment in GetDashboardOrderShipments(conn).ToList())
                //        {
                //            var statusCount = new Admin_Dashboard_StatusCountData()
                //            {
                //                StatusName = ctx.ShipmentStatusType(dbOrderShipment.OrderShipmentStatusTypeCode).Name,
                //                Count = dbOrderShipment.RecordCount.GetValueOrDefault()
                //            };
                //            statusCounts.Add(statusCount);
                //        }
                //        result.OrderShipmentStatusCounts = statusCounts;
                //    }
                //}

                log.Result(result);

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