Пример #1
0
        /// <summary>
        /// Submit Purchase Order
        /// </summary>
        /// <param name="purchaseOrderDataTransformation"></param>
        /// <returns></returns>
        public async Task <ResponseModel <PurchaseOrderDataTransformation> > SubmitPurchaseOrder(PurchaseOrderDataTransformation purchaseOrderDataTransformation)
        {
            ResponseModel <PurchaseOrderDataTransformation> returnResponse = new ResponseModel <PurchaseOrderDataTransformation>();

            PurchaseOrder purchaseOrder = new PurchaseOrder();

            int accountId       = purchaseOrderDataTransformation.AccountId;
            int purchaseOrderId = purchaseOrderDataTransformation.PurchaseOrderId;

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

                purchaseOrder = await _purchaseOrderManagementDataService.GetPurchaseOrder(accountId, purchaseOrderId);

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

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

                    return(returnResponse);
                }

                if (purchaseOrder.OrderTotal == 0.00)
                {
                    _purchaseOrderManagementDataService.RollbackTransaction();

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

                    return(returnResponse);
                }

                purchaseOrder.PurchaseOrderStatusId = PurchaseOrderStatuses.Submitted;

                await _purchaseOrderManagementDataService.UpdateDatabase();

                purchaseOrder = await _purchaseOrderManagementDataService.GetPurchaseOrder(accountId, purchaseOrderId);

                TransactionQueueOutbound transactionQueue = new TransactionQueueOutbound();
                transactionQueue.Payload         = GeneratePurchaseOrderSubmittedPayload(purchaseOrder);
                transactionQueue.TransactionCode = TransactionQueueTypes.PurchaseOrderSubmitted;
                transactionQueue.ExchangeName    = MessageQueueExchanges.PurchaseOrderManagement;

                await _purchaseOrderManagementDataService.CreateOutboundTransactionQueue(transactionQueue);

                //await _purchaseOrderManagementDataService.UpdateDatabase();

                _purchaseOrderManagementDataService.CommitTransaction();

                returnResponse.ReturnStatus = true;

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

            returnResponse.Entity = purchaseOrderDataTransformation;

            return(returnResponse);
        }