Example #1
0
        public Student Save()
        {
            bool      result   = true;
            StudentDB database = new StudentDB("Student");

            //OPEN CONNECTION BEGIN TRANSACTION
            database.BeginTransaction();

            if (base.isNew == true & IsSaveable() == true)
            {
                result = Insert(database);
            }
            else if (base.deleted == true && base.isDirty == true)
            {
                result = Delete(database);
            }
            else if (base.isNew == false && IsValid() == true)
            {
                result = Update(database);
            }
            if (result == true)
            {
                base.isNew   = false;
                base.isDirty = false;
            }

            //SAVE CHILDREN
            if (result == true && _Phones != null && _Phones.IsSaveable() == true)
            {
                _Phones.Save(database, base.id);
            }
            if (result == true && _Emails != null && _Emails.IsSaveable() == true)
            {
                _Emails.Save(database, base.id);
            }
            if (result == true && _Addresses != null && _Addresses.IsSaveable() == true)
            {
                _Addresses.Save(database, base.id);
            }
            //ALL DATA IS COMMITTED
            if (result == true)
            {
                database.EndTransaction();
            }
            else
            {
                database.Rollback();
            }

            return(this);
        }