/// <summary> /// Generate Purchase Order Submitted Payload /// </summary> /// <param name="purchaseOrder"></param> /// <returns></returns> private string GeneratePurchaseOrderSubmittedPayload(PurchaseOrder purchaseOrder) { PurchaseOrderUpdatePayload purchaseOrderUpdatePayload = new PurchaseOrderUpdatePayload(); purchaseOrderUpdatePayload.AccountId = purchaseOrder.AccountId; purchaseOrderUpdatePayload.PurchaseOrderId = purchaseOrder.PurchaseOrderId; purchaseOrderUpdatePayload.PurchaseOrderNumber = purchaseOrder.PurchaseOrderNumber; purchaseOrderUpdatePayload.PurchaseOrderStatusId = purchaseOrder.PurchaseOrderStatusId; purchaseOrderUpdatePayload.SupplierId = purchaseOrder.Supplier.SupplierId; purchaseOrderUpdatePayload.SupplierName = purchaseOrder.Supplier.Name; purchaseOrderUpdatePayload.AddressLine1 = purchaseOrder.Supplier.AddressLine1; purchaseOrderUpdatePayload.AddressLine2 = purchaseOrder.Supplier.AddressLine2; purchaseOrderUpdatePayload.City = purchaseOrder.Supplier.City; purchaseOrderUpdatePayload.Region = purchaseOrder.Supplier.Region; purchaseOrderUpdatePayload.PostalCode = purchaseOrder.Supplier.PostalCode; purchaseOrderUpdatePayload.OrderTotal = purchaseOrder.OrderTotal; purchaseOrderUpdatePayload.PurchaseOrderStatusDescription = purchaseOrder.PurchaseOrderStatus.Description; purchaseOrderUpdatePayload.DateCreated = purchaseOrder.DateCreated; purchaseOrderUpdatePayload.DateUpdated = purchaseOrder.DateUpdated; purchaseOrderUpdatePayload.PurchaseOrderDetails = new List <PurchaseOrderDetailUpdatePayload>(); foreach (PurchaseOrderDetail purchaseOrderDetail in purchaseOrder.PurchaseOrderDetails) { PurchaseOrderDetailUpdatePayload purchaseOrderDetailUpdatePayload = new PurchaseOrderDetailUpdatePayload(); purchaseOrderDetailUpdatePayload.PurchaseOrderDetailId = purchaseOrderDetail.PurchaseOrderDetailId; purchaseOrderDetailUpdatePayload.PurchaseOrderId = purchaseOrderDetail.PurchaseOrderId; purchaseOrderDetailUpdatePayload.ProductId = purchaseOrderDetail.ProductId; purchaseOrderDetailUpdatePayload.ProductMasterId = purchaseOrderDetail.Product.ProductMasterId; purchaseOrderDetailUpdatePayload.ProductNumber = purchaseOrderDetail.Product.ProductNumber; purchaseOrderDetailUpdatePayload.ProductDescription = purchaseOrderDetail.Product.Description; purchaseOrderDetailUpdatePayload.UnitPrice = purchaseOrderDetail.UnitPrice; purchaseOrderDetailUpdatePayload.OrderQuantity = purchaseOrderDetail.OrderQuantity; purchaseOrderDetailUpdatePayload.DateCreated = purchaseOrderDetail.DateCreated; purchaseOrderDetailUpdatePayload.DateUpdated = purchaseOrderDetail.DateUpdated; purchaseOrderUpdatePayload.PurchaseOrderDetails.Add(purchaseOrderDetailUpdatePayload); } string payload = SerializationFunction <PurchaseOrderUpdatePayload> .ReturnStringFromObject(purchaseOrderUpdatePayload); return(payload); }
/// <summary> /// Purchase Order Submitted /// </summary> /// <param name=""></param> private async Task PurchaseOrderSubmitted(TransactionQueueInbound transaction) { PurchaseOrderUpdatePayload payload = JsonConvert.DeserializeObject <PurchaseOrderUpdatePayload>(transaction.Payload); PurchaseOrder purchaseOrder = new PurchaseOrder(); purchaseOrder.AccountId = payload.AccountId; purchaseOrder.AddressLine1 = payload.AddressLine1; purchaseOrder.AddressLine2 = payload.AddressLine2; purchaseOrder.City = payload.City; purchaseOrder.Region = payload.Region; purchaseOrder.PostalCode = payload.PostalCode; purchaseOrder.SupplierName = payload.SupplierName; purchaseOrder.PurchaseOrderStatusId = PurchaseOrderStatuses.Open; purchaseOrder.PurchaseOrderNumber = payload.PurchaseOrderNumber; purchaseOrder.MasterPurchaseOrderId = payload.PurchaseOrderId; purchaseOrder.OrderTotal = payload.OrderTotal; await _inventoryManagementDataService.CreatePurchaseOrder(purchaseOrder); await _inventoryManagementDataService.UpdateDatabase(); foreach (PurchaseOrderDetailUpdatePayload detail in payload.PurchaseOrderDetails) { PurchaseOrderDetail purchaseOrderDetail = new PurchaseOrderDetail(); purchaseOrderDetail.AccountId = payload.AccountId; purchaseOrderDetail.MasterPurchaseOrderDetailId = detail.PurchaseOrderDetailId; purchaseOrderDetail.PurchaseOrderId = purchaseOrder.PurchaseOrderId; purchaseOrderDetail.ProductId = detail.ProductMasterId; purchaseOrderDetail.ProductNumber = detail.ProductNumber; purchaseOrderDetail.ProductDescription = detail.ProductDescription; purchaseOrderDetail.UnitPrice = detail.UnitPrice; purchaseOrderDetail.OrderQuantity = detail.OrderQuantity; purchaseOrderDetail.ReceivedQuantity = 0; purchaseOrderDetail.OrderTotal = detail.UnitPrice * detail.OrderQuantity; await _inventoryManagementDataService.CreatePurchaseOrderDetail(purchaseOrderDetail); } await LogSuccessfullyProcessed(transaction); }