예제 #1
0
        /// <summary>
        /// Inventory Received
        /// </summary>
        /// <param name="transaction"></param>
        private async Task InventoryReceived(TransactionQueueInbound transaction)
        {
            InventoryTransactionPayload payload = JsonConvert.DeserializeObject <InventoryTransactionPayload>(transaction.Payload);

            int purchaseOrderDetailId = payload.MasterEntityId;

            PurchaseOrderDetail purchaseOrderDetail = await _purchaseOrderManagementDataService.GetPurchaseOrderDetailForUpdate(purchaseOrderDetailId);

            if (purchaseOrderDetail != null)
            {
                purchaseOrderDetail.ReceiviedQuantity = purchaseOrderDetail.ReceiviedQuantity + payload.Quantity;

                await _purchaseOrderManagementDataService.UpdatePurchaseOrderDetail(purchaseOrderDetail);
            }

            await LogSuccessfullyProcessed(transaction);
        }
예제 #2
0
        /// <summary>
        /// Update Purchase Order Detail
        /// </summary>
        /// <param name="purchaseOrderDetailDataTransformation"></param>
        /// <returns></returns>
        public async Task <ResponseModel <PurchaseOrderDetailDataTransformation> > UpdatePurchaseOrderDetail(PurchaseOrderDetailDataTransformation purchaseOrderDetailDataTransformation)
        {
            ResponseModel <PurchaseOrderDetailDataTransformation> returnResponse = new ResponseModel <PurchaseOrderDetailDataTransformation>();

            PurchaseOrderDetail purchaseOrderDetail = new PurchaseOrderDetail();

            try
            {
                int accountId             = purchaseOrderDetailDataTransformation.AccountId;
                int purchaseOrderId       = purchaseOrderDetailDataTransformation.PurchaseOrderId;
                int purchaseOrderDetailId = purchaseOrderDetailDataTransformation.PurchaseOrderDetailId;

                _purchaseOrderManagementDataService.OpenConnection(_connectionStrings.PrimaryDatabaseConnectionString);
                _purchaseOrderManagementDataService.BeginTransaction((int)IsolationLevel.ReadCommitted);

                PurchaseOrderDetailBusinessRules <PurchaseOrderDetailDataTransformation> purchaseOrderDetailBusinessRules = new PurchaseOrderDetailBusinessRules <PurchaseOrderDetailDataTransformation>(purchaseOrderDetailDataTransformation);
                ValidationResult validationResult = purchaseOrderDetailBusinessRules.Validate();
                if (validationResult.ValidationStatus == false)
                {
                    _purchaseOrderManagementDataService.RollbackTransaction();

                    returnResponse.ReturnMessage = validationResult.ValidationMessages;
                    returnResponse.ReturnStatus  = validationResult.ValidationStatus;

                    return(returnResponse);
                }

                PurchaseOrder purchaseOrder = await _purchaseOrderManagementDataService.GetPurchaseOrderHeader(accountId, purchaseOrderId);

                if (purchaseOrder == null)
                {
                    _purchaseOrderManagementDataService.RollbackTransaction();

                    returnResponse.ReturnMessage.Add("Purchase Order not found");
                    returnResponse.ReturnStatus = false;

                    return(returnResponse);
                }

                purchaseOrderDetail = await _purchaseOrderManagementDataService.GetPurchaseOrderDetailForUpdate(purchaseOrderDetailId);

                if (purchaseOrderDetail == null)
                {
                    _purchaseOrderManagementDataService.RollbackTransaction();

                    returnResponse.ReturnMessage.Add("Purchase Order Detail not found");
                    returnResponse.ReturnStatus = false;

                    return(returnResponse);
                }

                double originalLineItemAmount = purchaseOrderDetail.OrderQuantity * purchaseOrderDetail.UnitPrice;
                double newLineItemAmount      = purchaseOrderDetailDataTransformation.UnitPrice * purchaseOrderDetailDataTransformation.OrderQuantity;

                purchaseOrder.OrderTotal = purchaseOrder.OrderTotal + newLineItemAmount - originalLineItemAmount;

                purchaseOrderDetailDataTransformation.OrderTotal = purchaseOrder.OrderTotal;

                await _purchaseOrderManagementDataService.UpdatePurchaseOrderHeader(purchaseOrder);

                purchaseOrderDetail.UnitPrice     = purchaseOrderDetailDataTransformation.UnitPrice;
                purchaseOrderDetail.OrderQuantity = purchaseOrderDetailDataTransformation.OrderQuantity;

                await _purchaseOrderManagementDataService.UpdatePurchaseOrderDetail(purchaseOrderDetail);

                //await _purchaseOrderManagementDataService.UpdateDatabase();

                _purchaseOrderManagementDataService.CommitTransaction();

                returnResponse.ReturnStatus = true;
            }
            catch (Exception ex)
            {
                _purchaseOrderManagementDataService.RollbackTransaction();
                returnResponse.ReturnStatus = false;
                returnResponse.ReturnMessage.Add(ex.Message);
            }
            finally
            {
                _purchaseOrderManagementDataService.CloseConnection();
            }

            returnResponse.Entity = purchaseOrderDetailDataTransformation;

            return(returnResponse);
        }