Exemplo n.º 1
0
        public void Child_Update(SystemRoleType systemRoleType, SqlConnection connection, SqlTransaction trans)
        {
            bool cancel = false;

            OnChildUpdating(systemRoleType, connection, ref cancel, trans);
            if (cancel)
            {
                return;
            }

            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }
            using (var command = new SqlCommand("[dbo].[spCFM_SystemRole_Update]", connection, trans))
            {
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@p_OriginalSystemRoleID", this.OriginalSystemRoleID);
                command.Parameters.AddWithValue("@p_SystemRoleID", this.SystemRoleID);
                command.Parameters.AddWithValue("@p_Code", this.Code);
                command.Parameters.AddWithValue("@p_Name", this.Name);
                command.Parameters.AddWithValue("@p_SystemRoleTypeID", systemRoleType != null ? systemRoleType.SystemRoleTypeID : this.SystemRoleTypeID);

                //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed.
                int result = command.ExecuteNonQuery();
                if (result == 0)
                {
                    throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                }

                // Update non-identity primary key value.
                _systemRoleIDProperty = (System.Int32)command.Parameters["@p_SystemRoleID"].Value;

                // Update foreign keys values. This code will update the values passed in from the parent only if no errors occurred after executing the query.
                if (systemRoleType != null && systemRoleType.SystemRoleTypeID != this.SystemRoleTypeID)
                {
                    _systemRoleTypeIDProperty = systemRoleType.SystemRoleTypeID;
                }

                // Update non-identity primary key value.
                _originalSystemRoleIDProperty = this.SystemRoleID;
            }

            // A child relationship exists on this Business Object but its type is not a child type (E.G. EditableChild).
            // TODO: Please override OnChildUpdated() and update this child manually.
            // UpdateChildren(this, null, connection);

            OnChildUpdated();
        }
Exemplo n.º 2
0
        public void Child_Insert(SystemRoleType systemRoleType, SqlConnection connection, SqlTransaction trans)
        {
            bool cancel = false;

            OnChildInserting(systemRoleType, connection, ref cancel, trans);
            if (cancel)
            {
                return;
            }

            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }
            using (var command = new SqlCommand("[dbo].[spCFM_SystemRole_Insert]", connection, trans))
            {
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@p_SystemRoleID", this.SystemRoleID);
                command.Parameters.AddWithValue("@p_Code", this.Code);
                command.Parameters.AddWithValue("@p_Name", this.Name);
                command.Parameters.AddWithValue("@p_SystemRoleTypeID", systemRoleType != null ? systemRoleType.SystemRoleTypeID : this.SystemRoleTypeID);

                command.ExecuteNonQuery();

                // Update foreign keys values. This code will update the values passed in from the parent only if no errors occurred after executing the query.
                if (systemRoleType != null && systemRoleType.SystemRoleTypeID != this.SystemRoleTypeID)
                {
                    _systemRoleTypeIDProperty = systemRoleType.SystemRoleTypeID;
                }

                // Update the original non-identity primary key value.
                _originalSystemRoleIDProperty = this.SystemRoleID;
            }

            // A child relationship exists on this Business Object but its type is not a child type (E.G. EditableChild).
            // TODO: Please override OnChildInserted() and insert this child manually.
            // UpdateChildren(this, null, connection);

            OnChildInserted();
        }
Exemplo n.º 3
0
 protected void UpdateChildren(SystemRoleType parent, SqlConnection connection, SqlTransaction trans)
 {
     if (_systemRolesPropertyChecked)
     {
         if (_systemRolesProperty != null)
         {
             foreach (SystemRole obj in _systemRolesProperty)
             {
                 if (obj.IsNew)
                 {
                     obj.Child_Insert(parent, connection, trans);
                 }
                 else
                 {
                     if (obj.IsDirty || obj.IsChildDirty())
                     {
                         obj.Child_Update(parent, connection, trans);
                     }
                 }
             }
         }
     }
 }
 /// <summary>
 /// CodeSmith generated stub method that is called when updating the child <see cref="SystemRole"/> object.
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="cancel">Value returned from the method indicating whether the object insertion should proceed.</param>
 partial void OnChildUpdating(SystemRoleType systemRoleType, SqlConnection connection, ref bool cancel, SqlTransaction trans);
        /// <summary>
        /// Creates a new object of type <see cref="SystemRoleType"/>.
        /// </summary>
        /// <returns>Returns a newly instantiated collection of type <see cref="SystemRoleType"/>.</returns>
        public static SystemRoleType NewSystemRoleType()
        {
            SystemRoleType obj = new SystemRoleType();

            return(obj);
        }
Exemplo n.º 6
0
        // [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Update()
        {
            bool cancel = false;

            OnUpdating(ref cancel);
            if (cancel)
            {
                return;
            }
            if (OriginalSystemRoleTypeID != SystemRoleTypeID)
            {
                // Insert new child.
                SystemRoleType item = new SystemRoleType {
                    SystemRoleTypeID = SystemRoleTypeID, Code = Code, Name = Name
                };

                item.DataPortal_Update();

                // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships.
                foreach (SystemRole itemToUpdate in SystemRoles)
                {
                    itemToUpdate.SystemRoleTypeID = SystemRoleTypeID;
                }

                // Create a new connection.
                using (var connection = new SqlConnection(ADOHelper.ConnectionString))
                {
                    connection.Open();
                    SqlTransaction trans = connection.BeginTransaction();
                    try
                    {
                        UpdateChildren(this, connection, trans);
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw;
                    }

                    //FieldManager.UpdateChildren(this, connection);
                }
                // Delete the old.
                var criteria = new SystemRoleTypeCriteria {
                    SystemRoleTypeID = OriginalSystemRoleTypeID
                };

                DataPortal_Delete(criteria);

                // Mark the original as the new one.
                OriginalSystemRoleTypeID = SystemRoleTypeID;
                OnUpdated();

                return;
            }

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                SqlTransaction trans = connection.BeginTransaction();
                try
                {
                    using (var command = new SqlCommand("[dbo].[spCFM_SystemRoleType_Update]", connection, trans))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_OriginalSystemRoleTypeID", this.OriginalSystemRoleTypeID);
                        command.Parameters.AddWithValue("@p_SystemRoleTypeID", this.SystemRoleTypeID);
                        command.Parameters.AddWithValue("@p_Code", this.Code);
                        command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                        //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed.
                        int result = command.ExecuteNonQuery();
                        if (result == 0)
                        {
                            throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                        }

                        _originalSystemRoleTypeIDProperty = this.SystemRoleTypeID;
                    }
                    UpdateChildren(this, connection, trans);
                    //FieldManager.UpdateChildren(this, connection);
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw;
                }
            }

            OnUpdated();
        }