Exemplo n.º 1
0
        /// <summary>
        /// Performs one "insert into" database command in a transactional context.
        /// * The method uses a transaction object already created and does not close the connection.
        /// * Must have "MultipleActiveResultSets=True" on connection string.
        /// </summary>
        /// <param name="OrdersInfo">Object to insert.</param>
        /// <param name="transaction">Inform "DBTransaction".</param>
        /// <param name="errorMessage">Error message if exception is throwed.</param>
        public virtual void InsertOne(OrdersInfo parOrdersInfo, DbTransaction transaction, out string errorMessage)
        {
            errorMessage = string.Empty;

//If is trying to insert FKValue without the ID but has the unique description,
//the system will try to get the class with the ID and populate it.
            if ((parOrdersInfo.CustomerID == null) && (parOrdersInfo.FK0_CompanyName != null))
            {
                CustomersInfo fkClass = Get_CustomerIDID_FKCustomers(parOrdersInfo, transaction);
                parOrdersInfo.CustomerID = fkClass.CustomerID;
            }
            if ((parOrdersInfo.EmployeeID == null) && (parOrdersInfo.FK1_LastName != null))
            {
                EmployeesInfo fkClass = Get_EmployeeIDID_FKEmployees(parOrdersInfo, transaction);
                parOrdersInfo.EmployeeID = fkClass.EmployeeID;
            }
            if ((parOrdersInfo.ShipVia == null) && (parOrdersInfo.FK2_CompanyName != null))
            {
                ShippersInfo fkClass = Get_ShipViaID_FKShippers(parOrdersInfo, transaction);
                parOrdersInfo.ShipVia = fkClass.ShipperID;
            }

            OrdersDAO.InsertOne(parOrdersInfo, transaction, out errorMessage);
            //By default, the caller of this method will do the commit.
            //motor.Commit();
            //motor.CloseConnection();
        }