Пример #1
0
        //[Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Delete(MailingTemplateCriteria 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_MailingTemplate_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();
        }
        public static void DeleteMailingTemplate(System.Int32 mailingTemplateID)
        {
            var criteria = new MailingTemplateCriteria {
                MailingTemplateID = mailingTemplateID
            };


            new MailingTemplate().DataPortal_Delete(criteria);
        }
        /// <summary>
        /// Returns a <see cref="MailingTemplate"/> object of the specified criteria.
        /// </summary>
        /// <param name="createdBy">No additional detail available.</param>
        /// <returns>A <see cref="MailingTemplate"/> object of the specified criteria.</returns>
        public static MailingTemplate GetByCreatedBy(System.Int32 createdBy)
        {
            var criteria = new MailingTemplateCriteria {
                CreatedBy = createdBy
            };


            return(new MailingTemplate().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// Returns a <see cref="MailingTemplate"/> object of the specified criteria.
        /// </summary>
        /// <param name="mailingTemplateID">No additional detail available.</param>
        /// <returns>A <see cref="MailingTemplate"/> object of the specified criteria.</returns>
        public static MailingTemplate GetByMailingTemplateID(System.Int32 mailingTemplateID)
        {
            var criteria = new MailingTemplateCriteria {
                MailingTemplateID = mailingTemplateID
            };


            return(new MailingTemplate().DataPortal_Fetch(criteria));
        }
        /// <summary>
        /// CodeSmith generated stub method that is called after the child <see cref="MailingTemplate"/> 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 MailingTemplate table in the database for the specified criteria.
        /// </summary>
        /// <param name="criteria">The criteria parameter is an <see cref="MailingTemplate"/> object.</param>
        /// <returns>A boolean value of true is returned if a record is found.</returns>
        public static MailingTemplate Exists(MailingTemplateCriteria criteria)
        {
            try
            {
                return(new MailingTemplate().DataPortal_Fetch(criteria));
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
        /// <summary>
        /// Returns a <see cref="MailingTemplate"/> object of the specified criteria.
        /// </summary>
        /// <param name="updatedBy">No additional detail available.</param>
        /// <returns>A <see cref="MailingTemplate"/> object of the specified criteria.</returns>
        public static MailingTemplate GetByUpdatedBy(System.Int32?updatedBy)
        {
            var criteria = new MailingTemplateCriteria {
            };

            if (updatedBy.HasValue)
            {
                criteria.UpdatedBy = updatedBy.Value;
            }

            return(new MailingTemplate().DataPortal_Fetch(criteria));
        }
        private MailingTemplateList DataPortal_Fetch(MailingTemplateCriteria 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_MailingTemplate_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_DescriptionHasValue", criteria.DescriptionHasValue);
                    command.Parameters.AddWithValue("@p_MailingTextHasValue", criteria.MailingTextHasValue);
                    command.Parameters.AddWithValue("@p_MailingSubjectHasValue", criteria.MailingSubjectHasValue);
                    command.Parameters.AddWithValue("@p_MailingFromHasValue", criteria.MailingFromHasValue);
                    command.Parameters.AddWithValue("@p_UpdatedByHasValue", criteria.UpdatedByHasValue);
                    command.Parameters.AddWithValue("@p_UpdatedOnHasValue", criteria.UpdatedOnHasValue);
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var rowParser = reader.GetRowParser <CFMData.MailingTemplate>();
                            do
                            {
                                this.Add(CFMData.MailingTemplate.GetMailingTemplate(rowParser, reader));
                            }while(reader.Read());
                        }
                        OnFetched();
                        return(this);
                    }
                }
            }

            //RaiseListChangedEvents = true;
        }
Пример #8
0
        private MailingTemplate DataPortal_Fetch(MailingTemplateCriteria 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_MailingTemplate_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_DescriptionHasValue", criteria.DescriptionHasValue);
                    command.Parameters.AddWithValue("@p_MailingTextHasValue", criteria.MailingTextHasValue);
                    command.Parameters.AddWithValue("@p_MailingSubjectHasValue", criteria.MailingSubjectHasValue);
                    command.Parameters.AddWithValue("@p_MailingFromHasValue", criteria.MailingFromHasValue);
                    command.Parameters.AddWithValue("@p_UpdatedByHasValue", criteria.UpdatedByHasValue);
                    command.Parameters.AddWithValue("@p_UpdatedOnHasValue", criteria.UpdatedOnHasValue);
                    using (var reader = command.ExecuteReader())
                    {
                        var rowParser = reader.GetRowParser <MailingTemplate>();
                        if (reader.Read())
                        {
                            return(GetMailingTemplate(rowParser, reader));
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.MailingTemplate' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }
            OnFetched();
        }
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the child <see cref="MailingTemplate"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="MailingTemplateCriteria"/> 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(MailingTemplateCriteria criteria, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the child <see cref="MailingTemplate"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="MailingTemplateCriteria"/> 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(MailingTemplateCriteria criteria, SqlConnection connection, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="MailingTemplate"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="MailingTemplateCriteria"/> 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 OnChildFetching(MailingTemplateCriteria criteria, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="MailingTemplate"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="MailingTemplateCriteria"/> 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(MailingTemplateCriteria criteria, ref bool cancel);
        public static MailingTemplateList GetByCriteria(MailingTemplateCriteria criteria)
        {
            return(new MailingTemplateList().DataPortal_Fetch(criteria));
//            return DataPortal.Fetch<MailingTemplateList>(criteria);
        }
Пример #13
0
        // [Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Update()
        {
            bool cancel = false;

            OnUpdating(ref cancel);
            if (cancel)
            {
                return;
            }
            if (OriginalMailingTemplateID != MailingTemplateID)
            {
                // Insert new child.
                MailingTemplate item = new MailingTemplate {
                    MailingTemplateID = MailingTemplateID, Description = Description, MailingText = MailingText, MailingSubject = MailingSubject, MailingFrom = MailingFrom, CreatedBy = CreatedBy, CreatedOn = CreatedOn
                };
                if (UpdatedBy.HasValue)
                {
                    item.UpdatedBy = UpdatedBy.Value;
                }
                if (UpdatedOn.HasValue)
                {
                    item.UpdatedOn = UpdatedOn.Value;
                }
                item.DataPortal_Update();

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

                // 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 MailingTemplateCriteria {
                    MailingTemplateID = OriginalMailingTemplateID
                };

                DataPortal_Delete(criteria);

                // Mark the original as the new one.
                OriginalMailingTemplateID = MailingTemplateID;
                OnUpdated();

                return;
            }

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                SqlTransaction trans = connection.BeginTransaction();
                try
                {
                    using (var command = new SqlCommand("[dbo].[spCFM_MailingTemplate_Update]", connection, trans))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_OriginalMailingTemplateID", this.OriginalMailingTemplateID);
                        command.Parameters.AddWithValue("@p_MailingTemplateID", this.MailingTemplateID);
                        command.Parameters.AddWithValue("@p_Description", ADOHelper.NullCheck(this.Description));
                        command.Parameters.AddWithValue("@p_MailingText", ADOHelper.NullCheck(this.MailingText));
                        command.Parameters.AddWithValue("@p_MailingSubject", ADOHelper.NullCheck(this.MailingSubject));
                        command.Parameters.AddWithValue("@p_MailingFrom", ADOHelper.NullCheck(this.MailingFrom));
                        command.Parameters.AddWithValue("@p_CreatedBy", this.CreatedBy);
                        command.Parameters.AddWithValue("@p_CreatedOn", this.CreatedOn);
                        command.Parameters.AddWithValue("@p_UpdatedBy", ADOHelper.NullCheck(this.UpdatedBy));
                        command.Parameters.AddWithValue("@p_UpdatedOn", ADOHelper.NullCheck(this.UpdatedOn));
                        //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.");
                        }

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

            OnUpdated();
        }