public static Dictionary <string, ProductColorDetails> GetProductColorOptions(long productId, string db) { Dictionary <string, ProductColorDetails> colorOptions = new Dictionary <string, ProductColorDetails>(); string query = "EXEC [stp_SS_GetProductColorOptions] @pId=" + productId; SqlConnection myConnection = new SqlConnection(db); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ProductColorDetails details = new ProductColorDetails(); details.colorId = dr["ColorId"].ToString().Replace("''", "'"); details.imageUrl = dr["ImageUrl"].ToString(); details.swatchUrl = dr["SwatchUrl"].ToString(); details.colorName = dr["ColorName"].ToString(); string defaultColorId = dr["DefaultColorId"].ToString(); details.isDefaultColor = (details.colorId == defaultColorId) ? true : false; colorOptions.Add(details.colorId, details); } } } finally { myConnection.Close(); } return(colorOptions); }
public static Dictionary<string, ProductColorDetails> GetProductColorOptions(long productId, string db) { Dictionary<string, ProductColorDetails> colorOptions = new Dictionary<string, ProductColorDetails>(); string query = "EXEC [stp_SS_GetProductColorOptions] @pId=" + productId; SqlConnection myConnection = new SqlConnection(db); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ProductColorDetails details = new ProductColorDetails(); details.colorId = dr["ColorId"].ToString().Replace("''", "'"); details.imageUrl = dr["ImageUrl"].ToString(); details.swatchUrl = dr["SwatchUrl"].ToString(); details.colorName = dr["ColorName"].ToString(); string defaultColorId = dr["DefaultColorId"].ToString(); details.isDefaultColor = (details.colorId == defaultColorId) ? true : false; colorOptions.Add(details.colorId, details); } } } finally { myConnection.Close(); } return colorOptions; }