예제 #1
0
 public void Child_Update(BudgetType budgetType, SqlConnection connection, SqlTransaction trans)
 {
     Child_Update(null, budgetType, null, null, connection, trans);
 }
예제 #2
0
        public void Child_Update(ApplicationUser applicationUser, BudgetType budgetType, Client client, Home home, SqlConnection connection, SqlTransaction trans)
        {
            bool cancel = false;

            OnChildUpdating(applicationUser, budgetType, client, home, connection, ref cancel, trans);
            if (cancel)
            {
                return;
            }

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

                command.Parameters.AddWithValue("@p_BudgetID", this.BudgetID);
                command.Parameters.AddWithValue("@p_BudgetTypeID", budgetType != null ? budgetType.BudgetTypeID : this.BudgetTypeID);
                command.Parameters.AddWithValue("@p_ClientID", ADOHelper.NullCheck(client != null ? client.ClientID : this.ClientID));
                command.Parameters.AddWithValue("@p_HomeID", ADOHelper.NullCheck(home != null ? home.HomeID : this.HomeID));
                command.Parameters.AddWithValue("@p_BudgetCode", this.BudgetCode);
                command.Parameters.AddWithValue("@p_EffectiveDate", this.EffectiveDate);
                command.Parameters.AddWithValue("@p_TemplateName", ADOHelper.NullCheck(this.TemplateName));
                command.Parameters.AddWithValue("@p_IsActive", this.IsActive);
                command.Parameters.AddWithValue("@p_CreatedBy", applicationUser != null ? applicationUser.ApplicationUserID : this.CreatedBy);
                command.Parameters.AddWithValue("@p_CreatedOn", this.CreatedOn);
                command.Parameters.AddWithValue("@p_UpdatedBy", ADOHelper.NullCheck(applicationUser != null ? applicationUser.ApplicationUserID : this.UpdatedBy));
                command.Parameters.AddWithValue("@p_UpdatedOn", ADOHelper.NullCheck(this.UpdatedOn));
                command.Parameters.AddWithValue("@p_EnteredMonthly", this.EnteredMonthly);
                command.Parameters.AddWithValue("@p_ScopeContribution", this.ScopeContribution);
                command.Parameters.AddWithValue("@p_NumberOfBeds", this.NumberOfBeds);
                command.Parameters.AddWithValue("@p_Vacancies", this.Vacancies);

                //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 foreign keys values. This code will update the values passed in from the parent only if no errors occurred after executing the query.
                if (budgetType != null && budgetType.BudgetTypeID != this.BudgetTypeID)
                {
                    _budgetTypeIDProperty = budgetType.BudgetTypeID;
                }

                // 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 (client != null && client.ClientID != this.ClientID)
                {
                    _clientIDProperty = client.ClientID;
                }

                // 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 (home != null && home.HomeID != this.HomeID)
                {
                    _homeIDProperty = home.HomeID;
                }

                // 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 (applicationUser != null && applicationUser.ApplicationUserID != this.CreatedBy)
                {
                    _createdByProperty = applicationUser.ApplicationUserID;
                }

                // 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 (applicationUser != null && applicationUser.ApplicationUserID != this.UpdatedBy)
                {
                    _updatedByProperty = applicationUser.ApplicationUserID;
                }
            }

            // 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, null, null, null, null, null, null, null, null, connection);

            OnChildUpdated();
        }
예제 #3
0
        public void Child_Insert(ApplicationUser applicationUser, BudgetType budgetType, Client client, Home home, SqlConnection connection, SqlTransaction trans)
        {
            bool cancel = false;

            OnChildInserting(applicationUser, budgetType, client, home, connection, ref cancel, trans);
            if (cancel)
            {
                return;
            }

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

                command.Parameters.AddWithValue("@p_BudgetID", this.BudgetID);
                command.Parameters["@p_BudgetID"].Direction = ParameterDirection.Output;
                command.Parameters.AddWithValue("@p_BudgetTypeID", budgetType != null ? budgetType.BudgetTypeID : this.BudgetTypeID);
                command.Parameters.AddWithValue("@p_ClientID", ADOHelper.NullCheck(client != null ? client.ClientID : this.ClientID));
                command.Parameters.AddWithValue("@p_HomeID", ADOHelper.NullCheck(home != null ? home.HomeID : this.HomeID));
                command.Parameters.AddWithValue("@p_BudgetCode", this.BudgetCode);
                command.Parameters.AddWithValue("@p_EffectiveDate", this.EffectiveDate);
                command.Parameters.AddWithValue("@p_TemplateName", ADOHelper.NullCheck(this.TemplateName));
                command.Parameters.AddWithValue("@p_IsActive", this.IsActive);
                command.Parameters.AddWithValue("@p_CreatedBy", applicationUser != null ? applicationUser.ApplicationUserID : this.CreatedBy);
                command.Parameters.AddWithValue("@p_CreatedOn", this.CreatedOn);
                command.Parameters.AddWithValue("@p_UpdatedBy", ADOHelper.NullCheck(applicationUser != null ? applicationUser.ApplicationUserID : this.UpdatedBy));
                command.Parameters.AddWithValue("@p_UpdatedOn", ADOHelper.NullCheck(this.UpdatedOn));
                command.Parameters.AddWithValue("@p_EnteredMonthly", this.EnteredMonthly);
                command.Parameters.AddWithValue("@p_ScopeContribution", this.ScopeContribution);
                command.Parameters.AddWithValue("@p_NumberOfBeds", this.NumberOfBeds);
                command.Parameters.AddWithValue("@p_Vacancies", this.Vacancies);

                command.ExecuteNonQuery();

                // Update identity primary key value.
                _budgetIDProperty = (System.Int32)command.Parameters["@p_BudgetID"].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 (budgetType != null && budgetType.BudgetTypeID != this.BudgetTypeID)
                {
                    _budgetTypeIDProperty = budgetType.BudgetTypeID;
                }

                // 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 (client != null && client.ClientID != this.ClientID)
                {
                    _clientIDProperty = client.ClientID;
                }

                // 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 (home != null && home.HomeID != this.HomeID)
                {
                    _homeIDProperty = home.HomeID;
                }

                // 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 (applicationUser != null && applicationUser.ApplicationUserID != this.CreatedBy)
                {
                    _createdByProperty = applicationUser.ApplicationUserID;
                }

                // 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 (applicationUser != null && applicationUser.ApplicationUserID != this.UpdatedBy)
                {
                    _updatedByProperty = applicationUser.ApplicationUserID;
                }
            }

            // 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, null, null, null, null, null, null, null, null, connection);

            OnChildInserted();
        }