public Gender GetGenderById(int id, string lang) { var gender = new Gender(); string commandText = "SELECT DISTINCT GENDER_LX_ID, GENDER_CODE, "; if (lang.Equals("fr")) { commandText += " FR_DESC as GENDER"; } else { commandText += " EN_DESC as GENDER"; } commandText += " FROM CVPONL_OWNER.GENDER_LX WHERE GENDER_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 Gender(); item.gender_id = dr["GENDER_LX_ID"] == DBNull.Value ? 0 : Convert.ToInt32(dr["GENDER_LX_ID"]); item.gender_code = dr["GENDER_CODE"] == DBNull.Value ? string.Empty : dr["GENDER_CODE"].ToString().Trim(); item.gender_name = dr["GENDER"] == DBNull.Value ? string.Empty : dr["GENDER"].ToString().Trim(); gender = item; } } } } catch (Exception ex) { string errorMessages = string.Format("DbConnection.cs - GetGenderById()"); ExceptionHelper.LogException(ex, errorMessages); Console.WriteLine(errorMessages); } finally { if (con.State == ConnectionState.Open) con.Close(); } } return gender; }
public Gender Get(int id, string lang) { _gender = dbConnection.GetGenderById(id, lang); return _gender; }