public List <Product> GetAllProducts() { var command = new SqlCommand("select id, name, description, price from products"); var dt = MsSqlDatabaseHelpers.GetDataTable(command, ConnectionString); return(dt.AsEnumerable().Select(r => GenerateProductFromDataRow(r)).ToList()); }
public Product GetProductById(int id) { var command = new SqlCommand("select id, name, description, price from products where id=@id"); command.Parameters.AddWithValue("id", id); var dt = MsSqlDatabaseHelpers.GetDataTable(command, ConnectionString); return(dt.AsEnumerable().Select(r => GenerateProductFromDataRow(r)).Single()); }
private bool ProductsTableExists() { var command = new SqlCommand("select table_name from information_schema.tables where table_type='BASE TABLE' and table_name=@name"); command.Parameters.AddWithValue("name", "products"); var dt = MsSqlDatabaseHelpers.GetDataTable(command, ConnectionString); if (dt.Rows.Count > 0) { return(true); } else { return(false); } }