Example #1
0
        public override PlanExtra Save()
        {
            // Por la posible doble interfaz Root/Child
            if (IsChild)
            {
                throw new iQException(moleQule.Library.Resources.Messages.CHILD_SAVE_NOT_ALLOWED);
            }

            if (IsDeleted && !CanDeleteObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (IsNew && !CanAddObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (!CanEditObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }

            try
            {
                ValidationRules.CheckRules();

                base.Save();

                _c_extras.Update(this);

                if (!SharedTransaction)
                {
                    Transaction().Commit();
                }
                return(this);
            }
            catch (Exception ex)
            {
                if (!SharedTransaction)
                {
                    if (!SharedTransaction && Transaction() != null)
                    {
                        Transaction().Rollback();
                    }
                }
                iQExceptionHandler.TreatException(ex);
                return(this);
            }
            finally
            {
                if (!SharedTransaction)
                {
                    if (CloseSessions && (this.IsNew || Transaction().WasCommitted))
                    {
                        CloseSession();
                    }
                    else
                    {
                        BeginTransaction();
                    }
                }
            }
        }