/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(CProfile_system businessObject, IDataReader dataReader) { businessObject.Idprofile = (short)dataReader.GetInt16(dataReader.GetOrdinal(CProfile_system.CProfile_systemFields.Idprofile.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(CProfile_system.CProfile_systemFields.Profile_name.ToString()))) { businessObject.Profile_name = dataReader.GetString(dataReader.GetOrdinal(CProfile_system.CProfile_systemFields.Profile_name.ToString())); } }
/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of CProfile_system</returns> internal List <CProfile_system> PopulateObjectsFromReader(IDataReader dataReader) { List <CProfile_system> list = new List <CProfile_system>(); while (dataReader.Read()) { CProfile_system businessObject = new CProfile_system(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>CProfile_system business object</returns> public CProfile_system SelectByPrimaryKey(CProfile_systemKeys keys) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_profile_system_SelectByPrimaryKey"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new NpgsqlParameter("p_idprofile", NpgsqlDbType.Smallint, 2, "", ParameterDirection.Input, false, 0, 0, DataRowVersion.Proposed, keys.Idprofile)); MainConnection.Open(); NpgsqlDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { CProfile_system businessObject = new CProfile_system(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("CProfile_system::SelectByPrimaryKey::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(CProfile_system businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_profile_system_Insert"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idprofile", businessObject.Idprofile); sqlCommand.Parameters["p_idprofile"].NpgsqlDbType = NpgsqlDbType.Smallint; sqlCommand.Parameters["p_idprofile"].Direction = ParameterDirection.InputOutput; sqlCommand.Parameters.AddWithValue("p_profile_name", businessObject.Profile_name); sqlCommand.Parameters["p_profile_name"].NpgsqlDbType = NpgsqlDbType.Varchar; MainConnection.Open(); sqlCommand.ExecuteNonQuery(); businessObject.Idprofile = Convert.ToInt16(sqlCommand.Parameters["p_idprofile"].Value); return(true); } catch (Exception ex) { throw new Exception("CProfile_system::Insert::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
/// <summary> /// update row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true for successfully updated</returns> public bool Update(CProfile_system businessObject) { NpgsqlCommand sqlCommand = new NpgsqlCommand(); sqlCommand.CommandText = "public.sp_profile_system_Update"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.AddWithValue("p_idprofile", businessObject.Idprofile); sqlCommand.Parameters["p_idprofile"].NpgsqlDbType = NpgsqlDbType.Smallint; sqlCommand.Parameters.AddWithValue("p_profile_name", businessObject.Profile_name); sqlCommand.Parameters["p_profile_name"].NpgsqlDbType = NpgsqlDbType.Varchar; MainConnection.Open(); if (Convert.ToInt32(sqlCommand.ExecuteScalar()) > 0) { return(true); } return(false); } catch (Exception ex) { throw new Exception("CProfile_system::Update::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }