예제 #1
0
        /// <summary>
        /// Create Purchase Order
        /// </summary>
        /// <param name="purchaseOrderDataTransformation"></param>
        /// <returns></returns>
        public async Task <ResponseModel <PurchaseOrderDataTransformation> > CreatePurchaseOrder(PurchaseOrderDataTransformation purchaseOrderDataTransformation)
        {
            ResponseModel <PurchaseOrderDataTransformation> returnResponse = new ResponseModel <PurchaseOrderDataTransformation>();

            PurchaseOrder purchaseOrder = new PurchaseOrder();

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

                PurchaseOrderNumberSequence purchaseOrderNumberSequence = await _purchaseOrderManagementDataService.GetPurchaseOrderNumberSequence(purchaseOrderDataTransformation.AccountId);

                if (purchaseOrderNumberSequence == null)
                {
                    purchaseOrderNumberSequence                     = new PurchaseOrderNumberSequence();
                    purchaseOrderNumberSequence.AccountId           = purchaseOrderDataTransformation.AccountId;
                    purchaseOrderNumberSequence.PurchaseOrderNumber = 100000;
                    await _purchaseOrderManagementDataService.CreatePurchaseOrderNumberSequence(purchaseOrderNumberSequence);
                }
                else
                {
                    purchaseOrderNumberSequence.PurchaseOrderNumber = purchaseOrderNumberSequence.PurchaseOrderNumber + 1;
                    await _purchaseOrderManagementDataService.UpdatePurchaseOrderNumberSequence(purchaseOrderNumberSequence);
                }

                purchaseOrder.PurchaseOrderNumber   = purchaseOrderNumberSequence.PurchaseOrderNumber;
                purchaseOrder.AccountId             = purchaseOrderDataTransformation.AccountId;
                purchaseOrder.SupplierId            = purchaseOrderDataTransformation.SupplierId;
                purchaseOrder.PurchaseOrderStatusId = PurchaseOrderStatuses.Open;
                purchaseOrder.OrderTotal            = 0.0;

                await _purchaseOrderManagementDataService.CreatePurchaseOrder(purchaseOrder);

                //await _purchaseOrderManagementDataService.UpdateDatabase();

                _purchaseOrderManagementDataService.CommitTransaction();

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

            purchaseOrderDataTransformation.PurchaseOrderId = purchaseOrder.PurchaseOrderId;

            returnResponse.Entity = purchaseOrderDataTransformation;

            return(returnResponse);
        }