/// <summary> /// update row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true for successfully updated</returns> public bool Update($CLASS_NAME$ businessObject) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "$TABLE_SCHEMA$.[$SP_PREFIX$$TABLE_NAME$_Update]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { $UPDATE_PARAMETER$ MainConnection.Open(); sqlCommand.ExecuteNonQuery(); return(true); } catch (Exception ex) { throw new Exception("$CLASS_NAME$::Update::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// Delete by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>true for successfully deleted</returns> public bool Delete($CLASS_NAME$Keys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "$TABLE_SCHEMA$.[$SP_PREFIX$$TABLE_NAME$_DeleteByPrimaryKey]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { $SELECT_BY_PK_PARAMETERS$ MainConnection.Open(); sqlCommand.ExecuteNonQuery(); return(true); } catch (Exception ex) { throw new Exception("$CLASS_NAME$::DeleteByKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// insert new row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true of successfully insert</returns> public bool Insert($CLASS_NAME$ businessObject) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "$TABLE_SCHEMA$.[$SP_PREFIX$$TABLE_NAME$_Insert]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { $INSERT_PARAMETER$ MainConnection.Open(); sqlCommand.ExecuteNonQuery(); $GET_RETURNED_VALUE$ return(true); } catch (Exception ex) { throw new Exception("$CLASS_NAME$::Insert::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// Update existing $CLASS_NAME$ /// </summary> /// <param name="businessObject">$CLASS_NAME$ object</param> /// <returns>true for successfully saved</returns> public bool Update($CLASS_NAME$ businessObject) { if (!businessObject.IsValid) { throw new InvalidBusinessObjectException(businessObject.BrokenRulesList.ToString()); } return(_dataObject.Update(businessObject)); }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>$CLASS_NAME$ business object</returns> public $CLASS_NAME$ SelectByPrimaryKey($CLASS_NAME$Keys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "$TABLE_SCHEMA$.[$SP_PREFIX$$TABLE_NAME$_SelectByPrimaryKey]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { $SELECT_BY_PK_PARAMETERS$ MainConnection.Open(); IDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { $CLASS_NAME$ businessObject = new $CLASS_NAME$(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("$CLASS_NAME$::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader($CLASS_NAME$ businessObject, IDataReader dataReader) { $POPULATE_BUSINESS_OBJECT_PARAMERTERS$ }
/// <summary> /// get list of $CLASS_NAME$ by field /// </summary> /// <param name="fieldName">field name</param> /// <param name="value">value</param> /// <returns>list</returns> public List <$CLASS_NAME$> GetAllBy($CLASS_NAME$.$CLASS_NAME$Fields fieldName, object value)
/// <summary> /// get $CLASS_NAME$ by primary key. /// </summary> /// <param name="keys">primary key</param> /// <returns>Student</returns> public $CLASS_NAME$ GetByPrimaryKey($CLASS_NAME$Keys keys) { return(_dataObject.SelectByPrimaryKey(keys)); }