예제 #1
0
        //[Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Delete(SystemRoleTypeCriteria criteria)
        {
            bool cancel = false;

            OnDeleting(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[spCFM_SystemRoleType_Delete]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    //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.");
                    }
                }
            }

            OnDeleted();
        }
예제 #2
0
        private SystemRoleType DataPortal_Fetch(SystemRoleTypeCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(null);
            }
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[spCFM_SystemRoleType_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                    using (var reader = command.ExecuteReader())
                    {
                        var rowParser = reader.GetRowParser <SystemRoleType>();
                        if (reader.Read())
                        {
                            return(GetSystemRoleType(rowParser, reader));
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.SystemRoleType' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }
            OnFetched();
        }
        /// <summary>
        /// Returns a <see cref="SystemRoleTypeList"/> object of the specified criteria.
        /// </summary>
        /// <param name="systemRoleTypeID">No additional detail available.</param>
        /// <returns>A <see cref="SystemRoleTypeList"/> object of the specified criteria.</returns>
        public static SystemRoleTypeList GetBySystemRoleTypeID(System.Int32 systemRoleTypeID)
        {
            var criteria = new SystemRoleTypeCriteria {
                SystemRoleTypeID = systemRoleTypeID
            };


            return(new SystemRoleTypeList().DataPortal_Fetch(criteria));
        }
        public static void DeleteSystemRoleType(System.Int32 systemRoleTypeID)
        {
            var criteria = new SystemRoleTypeCriteria {
                SystemRoleTypeID = systemRoleTypeID
            };


            new SystemRoleType().DataPortal_Delete(criteria);
        }
        /// <summary>
        /// CodeSmith generated stub method that is called after the child <see cref="SystemRoleType"/> object with the specified criteria has been deleted.
        /// </summary>
        //partial void OnDeleted();
        //partial void OnChildLoading(Csla.Core.IPropertyInfo childProperty, ref bool cancel);

        #endregion


        #region Exists Command

        /// <summary>
        /// Determines if a record exists in the SystemRoleType table in the database for the specified criteria.
        /// </summary>
        /// <param name="criteria">The criteria parameter is an <see cref="SystemRoleType"/> object.</param>
        /// <returns>A boolean value of true is returned if a record is found.</returns>
        public static SystemRoleType Exists(SystemRoleTypeCriteria criteria)
        {
            try
            {
                return(new SystemRoleType().DataPortal_Fetch(criteria));
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
        private SystemRoleTypeList DataPortal_Fetch(SystemRoleTypeCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(null);
            }

            //RaiseListChangedEvents = false;

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[spCFM_SystemRoleType_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var rowParser = reader.GetRowParser <CFMData.SystemRoleType>();
                            do
                            {
                                this.Add(CFMData.SystemRoleType.GetSystemRoleType(rowParser, reader));
                            }while(reader.Read());
                        }
                        OnFetched();
                        return(this);
                    }
                }
            }

            //RaiseListChangedEvents = true;
        }
        public static SystemRoleTypeList GetByCriteria(SystemRoleTypeCriteria criteria)
        {
            return(new SystemRoleTypeList().DataPortal_Fetch(criteria));
//            return DataPortal.Fetch<SystemRoleTypeList>(criteria);
        }
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="SystemRoleType"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="SystemRoleTypeCriteria"/> object containing the criteria of the object to fetch.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param>
 partial void OnFetching(SystemRoleTypeCriteria criteria, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the child <see cref="SystemRoleType"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="SystemRoleTypeCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 //partial void OnDeleting(SystemRoleTypeCriteria criteria, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the child <see cref="SystemRoleType"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="SystemRoleTypeCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="connection"></param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(SystemRoleTypeCriteria criteria, SqlConnection connection, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="SystemRoleType"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="SystemRoleTypeCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(SystemRoleTypeCriteria criteria, ref bool cancel);
예제 #11
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();
        }