Пример #1
0
        /*
         * **************************************** My changes START here ************************************************
         */

        //private connection = null;
        //private SqlCommand command;
        // private bool insertReady;

        /*
         * <summary>
         * Updates student records in the Database
         * </summary>
         * <returns></returns>
         */

        public void Update()
        {
            IDbTransaction transaction = null;

            try
            {
                // Create a transaction to ensure all child properties are inserted along with the student record
                transaction = DataServiceBase.BeginTransaction();

                //Create a Student Data Service object with the transction object
                StudentDataService dataService = new StudentDataService(transaction);

                //Call the insert method
                dataService.Update(_studentID, _last4Ssn, _firstName, _lastName, _phoneCell, _phoneDay, _phoneEvening,
                                   _email, _address, _city, _state, _zipcode, _gpa, _graduationDate);

                // Update the Internship Requirement Child Object with the transaction
                _internshipRequirement.Update(_studentID, transaction);


                // Update employer if exists
                if (_employer != null)
                {
                    _employer.Update(_studentID, transaction);
                }

                // Commit the Transaction, ensures all child properites are updated along with the studento Objects
                transaction.Commit();
            }

            /*catch
             * {
             *  // Remove all records from the database if an error occurs
             *  transaction.Rollback();
             *  throw;
             * }*/

            catch (Exception ex)
            {
                // Remove all records from the database if an error occurs
                transaction.Rollback();
                // throw new System.Exception(ex.Message);
                throw new System.Exception("Exception: '" + ex.Message + "' occured while updating data! All transactions have been removed from database!");
            }
        }
Пример #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //This is just an example and is not meant to actually run
        if (false)
        {
            Person personA = Person.GetByPersonID(1);
            Person personB = Person.GetByPersonID(2);
            Person personC = Person.GetByPersonID(3);

            IDbTransaction txn = DataServiceBase.BeginTransaction();
            try
            {
                personA.Save(txn);
                personB.Save(txn);
                personC.Delete(txn);
                txn.Commit();
            }
            catch
            {
                //An error occured so roll the transaction back
                txn.Rollback();
            }
        }
    }