private Categories(CategoriesBuilder builder) { this.categoryID = builder.GetCategoryID; this.CategoryName = builder.GetCategoryName; this.description = builder.GetDescription; this.picture = builder.GetPictureField; }
public List <Categories> getAllCategories() { List <Categories> categoriesList = new List <Categories>(); Connection conn = new Connection(); SqlConnection connection = conn.SqlConnection; using (SqlCommand command = new SqlCommand("select * from Categories", connection)) { try { connection.Open(); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { Categories category = new CategoriesBuilder(dataReader.GetInt32(0), dataReader.GetString(1)) .Description(dataReader.IsDBNull(2) ? (string)null : dataReader.GetString(2)) .Picture(dataReader.IsDBNull(3) ? null : (byte[])(dataReader.GetValue(3))) .Build(); categoriesList.Add(category); } dataReader.Close(); } catch (Exception exc) { logger.logError(DateTime.Now, "Error while trying to get all categories."); MessageBox.Show(exc.Message); } logger.logInfo(DateTime.Now, "GetAllCategories method has sucessfully invoked."); return(categoriesList); } }
public void addCategory() { Categories category = new CategoriesBuilder("New Category").Build(); index = repo.addCategory(category); Assert.IsTrue(index != 0); }
public Categories getCategoryById(int categoryID) { Categories category = null; Connection conn = new Connection(); SqlConnection connection = conn.SqlConnection; SqlCommand selectCommand = new SqlCommand(); selectCommand.Connection = connection; selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.CommandText = "GetCategoryById"; selectCommand.Parameters.Add("@CategoryID", SqlDbType.Int); selectCommand.Parameters["@CategoryID"].Value = categoryID; { try { connection.Open(); SqlDataReader dataReader = selectCommand.ExecuteReader(); if (dataReader.HasRows) { dataReader.Read(); category = new CategoriesBuilder(dataReader.GetInt32(0), dataReader.GetString(1)) .Description(dataReader.IsDBNull(2) ? (string)null : dataReader.GetString(2)) .Picture(dataReader.IsDBNull(3) ? null : (byte[])(dataReader.GetValue(3))) .Build(); } dataReader.Close(); } catch (Exception exc) { logger.logError(DateTime.Now, "Error while trying to get categoriy with CategoryID = " + categoryID + "."); MessageBox.Show(exc.Message); } finally { connection.Close(); } logger.logInfo(DateTime.Now, "GetCategoryById method has sucessfully invoked."); return(category); } }