public void Child_Update(ApplicationUser applicationUser, SystemRole systemRole, SqlConnection connection, SqlTransaction trans) { bool cancel = false; OnChildUpdating(applicationUser, systemRole, connection, ref cancel, trans); if (cancel) { return; } if (connection.State != ConnectionState.Open) { connection.Open(); } using (var command = new SqlCommand("[dbo].[spCFM_ApplicationRole_Update]", connection, trans)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_ApplicationRoleID", this.ApplicationRoleID); command.Parameters.AddWithValue("@p_Name", this.Name); command.Parameters.AddWithValue("@p_SystemRoleID", systemRole != null ? systemRole.SystemRoleID : this.SystemRoleID); command.Parameters.AddWithValue("@p_IsSystemRole", this.IsSystemRole); 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)); //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 (systemRole != null && systemRole.SystemRoleID != this.SystemRoleID) { _systemRoleIDProperty = systemRole.SystemRoleID; } // 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, connection); OnChildUpdated(); }
public void LoadSystemRoleType(SystemRole obj) { if (obj.SystemRoleType != null) { _systemRoleTypeProperty = obj.SystemRoleType.CurrentDTO; } }
// OneToMany public void LoadApplicationRoles(SystemRole obj) { if (obj.ApplicationRoles != null) { _applicationRolesProperty = obj.ApplicationRoles.CurrentDTO; } }
public void Child_Insert(ApplicationUser applicationUser, SystemRole systemRole, SqlConnection connection, SqlTransaction trans) { bool cancel = false; OnChildInserting(applicationUser, systemRole, connection, ref cancel, trans); if (cancel) { return; } if (connection.State != ConnectionState.Open) { connection.Open(); } using (var command = new SqlCommand("[dbo].[spCFM_ApplicationRole_Insert]", connection, trans)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_ApplicationRoleID", this.ApplicationRoleID); command.Parameters["@p_ApplicationRoleID"].Direction = ParameterDirection.Output; command.Parameters.AddWithValue("@p_Name", this.Name); command.Parameters.AddWithValue("@p_SystemRoleID", systemRole != null ? systemRole.SystemRoleID : this.SystemRoleID); command.Parameters.AddWithValue("@p_IsSystemRole", this.IsSystemRole); 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.ExecuteNonQuery(); // Update identity primary key value. _applicationRoleIDProperty = (System.Int32)command.Parameters["@p_ApplicationRoleID"].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 (systemRole != null && systemRole.SystemRoleID != this.SystemRoleID) { _systemRoleIDProperty = systemRole.SystemRoleID; } // 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, connection); OnChildInserted(); }
public SystemRole CopyDTO(SystemRole obj) { obj.SystemRoleID = this.SystemRoleID; obj.Code = this.Code; obj.Name = this.Name; obj.SystemRoleTypeID = this.SystemRoleTypeID; return(obj); }
public static SystemRole GetSystemRole(Func <IDataReader, SystemRole> rowParser, SqlDataReader reader) { SystemRole obj = rowParser(reader); obj.InitDTO(); obj.IsDirty = false; obj.IsNew = false; return(obj); }
protected void UpdateChildren(SystemRole parent, SqlConnection connection, SqlTransaction trans) { if (_applicationRolesPropertyChecked) { if (_applicationRolesProperty != null) { foreach (ApplicationRole obj in _applicationRolesProperty) { 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="ApplicationRole"/> 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(ApplicationUser applicationUser, SystemRole systemRole, SqlConnection connection, ref bool cancel, SqlTransaction trans);
/// <summary> /// Creates a new object of type <see cref="SystemRole"/>. /// </summary> /// <returns>Returns a newly instantiated collection of type <see cref="SystemRole"/>.</returns> public static SystemRole NewSystemRole() { SystemRole obj = new SystemRole(); return(obj); }
public void Child_Update(SystemRole systemRole, SqlConnection connection, SqlTransaction trans) { Child_Update(null, systemRole, connection, trans); }
// [Transactional(TransactionalTypes.TransactionScope)] protected void DataPortal_Update() { bool cancel = false; OnUpdating(ref cancel); if (cancel) { return; } if (OriginalSystemRoleID != SystemRoleID) { // Insert new child. SystemRole item = new SystemRole { SystemRoleID = SystemRoleID, Code = Code, Name = Name, SystemRoleTypeID = SystemRoleTypeID }; item.DataPortal_Update(); // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships. foreach (ApplicationRole itemToUpdate in ApplicationRoles) { itemToUpdate.SystemRoleID = SystemRoleID; } // 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 SystemRoleCriteria { SystemRoleID = OriginalSystemRoleID }; DataPortal_Delete(criteria); // Mark the original as the new one. OriginalSystemRoleID = SystemRoleID; OnUpdated(); return; } using (var connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); SqlTransaction trans = connection.BeginTransaction(); try { 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", 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."); } _originalSystemRoleIDProperty = this.SystemRoleID; } UpdateChildren(this, connection, trans); //FieldManager.UpdateChildren(this, connection); trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw; } } OnUpdated(); }