public List <Product> GetList() { try { using (var connection = new SqlConnection(_connectionString)) { var commandText = "SELECT * FROM Products"; var command = new SqlCommand(commandText, connection); connection.Open(); using (var reader = command.ExecuteReader()) { if (!reader.HasRows) { return(null); } return(ProviderUtility.DataReaderMapToList <Product>(reader)); } } } catch (Exception) { throw; } }
public List <Product> Search(string query) { try { using (var connection = new SqlConnection(_connectionString)) { var command = new SqlCommand(ProductStoredProcedures.Search, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Query", query); connection.Open(); using (var reader = command.ExecuteReader()) { if (!reader.HasRows) { return(null); } var results = ProviderUtility.DataReaderMapToList <Product>(reader); return(results); } } } catch (Exception) { throw; } }