/// <summary> /// Gets the one. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public Category GetOne(int id) { string sqlStatement = "select * from Categories where CategoryID = @CategoryID"; var item = new Category(); using (var conn = this.CreateGlimpseDbConnection()) using (var command = new GlimpseDbCommand(new SqlCommand())) { command.Connection = conn; command.CommandType = CommandType.Text; command.CommandTimeout = 180; command.CommandText = sqlStatement; command.Parameters.Add(new SqlParameter("CategoryID", id)); if (conn.State != ConnectionState.Open) conn.Open(); using (IDataReader reader = command.ExecuteReader()) { if (reader.Read()) { item.CategoryID = int.Parse(reader["CategoryID"].ToString()); item.CategoryName = reader["CategoryName"].ToString(); item.Description = reader["Description"].ToString(); } } } return item; }
/// <summary> /// Gets the categories. /// </summary> /// <returns></returns> public List<Category> GetCategories() { var categories = new List<Category>(); string sqlStatement = "select * from Categories order by CategoryID desc"; using (var conn = this.CreateGlimpseDbConnection()) using (var command = new GlimpseDbCommand(new SqlCommand())) { command.Connection = conn; command.CommandType = CommandType.Text; command.CommandTimeout = 180; command.CommandText = sqlStatement; if (conn.State != ConnectionState.Open) conn.Open(); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var item = new Category { CategoryID = int.Parse(reader["CategoryID"].ToString()), CategoryName = reader["CategoryName"].ToString(), Description = reader["Description"].ToString() }; categories.Add(item); } } } return categories; }