public IEnumerable <Dictionary <string, object> > GetProducts(int storeId) { string storedProcedureName = "pujan_sp_get_customfield_data"; var parameters = new Dictionary <string, object>(); parameters.Add("@StoreId", storeId); using (SqlConnection connection = _adoDotNetHelper.GetSqlConnection()) { try { connection.Open(); } catch (Exception e) { _loggingService.Write(e, LogLevel.Error, typeof(ProductDataRepository), true); throw; } using (SqlCommand command = _adoDotNetHelper.GetSqlCommand( storedProcedureName, parameters, true )) { command.Connection = connection; command.CommandTimeout = 0; using (SqlDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { //return null; var columns = Enumerable.Range(0, reader.FieldCount).Select(reader.GetName).ToList(); if (columns.Any()) { int count = 0; while (reader.Read()) { var product = new Dictionary <string, object>(); foreach (var column in columns) { if (!product.ContainsKey(column)) { product.Add(column, reader[column]); } else { product.Add(column + "_1", reader[column]); } } yield return(product); } } } } } } }
public List <StoreModel> GetStores() { string sql = @"Select Id,StoreIdentifier,Name,ClientId From store "; //Where Id not in (32,48,21,49,39,58) var stores = new List <StoreModel>(); try { using (SqlConnection connection = _adoDotNetHelper.GetSqlConnection()) { connection.Open(); using (SqlCommand command = _adoDotNetHelper.GetSqlCommand(sql)) { command.Connection = connection; using (SqlDataReader reader = command.ExecuteReader()) { if (!reader.HasRows) { return(null); } while (reader.Read()) { stores.Add(new StoreModel() { Name = reader["Name"].ToString(), ClientId = Convert.ToInt32(reader["ClientId"].ToString()), StoreId = Convert.ToInt32(reader["Id"].ToString()), StoreIdentifier = reader["StoreIdentifier"].ToString() }); } } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); } return(stores); }