public Source GetSourceById(int id, string lang) { var source = new Source(); string commandText = "SELECT DISTINCT SOURCE_LX_ID, SOURCE_CODE,"; if (lang.Equals("fr")) { commandText += " FR_DESC as SOURCE"; } else { commandText += " EN_DESC as SOURCE"; } commandText += " FROM CVPONL_OWNER.SOURCE_LX WHERE SOURCE_LX_ID = " + id; using ( OracleConnection con = new OracleConnection(DpdDBConnection)) { OracleCommand cmd = new OracleCommand(commandText, con); try { con.Open(); using (OracleDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { while (dr.Read()) { var item = new Source(); item.source_id = dr["SOURCE_LX_ID"] == DBNull.Value ? 0 : Convert.ToInt32(dr["SOURCE_LX_ID"]); item.source_code = dr["SOURCE_CODE"] == DBNull.Value ? string.Empty : dr["SOURCE_CODE"].ToString().Trim(); item.source = dr["SOURCE"] == DBNull.Value ? string.Empty : dr["SOURCE"].ToString().Trim(); source = item; } } } } catch (Exception ex) { string errorMessages = string.Format("DbConnection.cs - GetSourceById()"); ExceptionHelper.LogException(ex, errorMessages); Console.WriteLine(errorMessages); } finally { if (con.State == ConnectionState.Open) con.Close(); } } return source; }
public Source Get(int id, string lang) { _source = dbConnection.GetSourceById(id, lang); return _source; }