/// <summary> /// The create category. /// </summary> /// <param name="categoryName"> /// The category name. /// </param> /// <returns> /// The <see cref="Category"/>. /// </returns> /// <exception cref="Exception"> /// </exception> public Category CreateCategory(string categoryName) { Category category = new Category(); category.CategoryName = categoryName; SqlParameter[] sqlParameters = new SqlParameter[1]; sqlParameters[0] = new SqlParameter("@CategoryName", SqlDbType.VarChar) { Value = categoryName }; try { category.CategoryID = sqlDalManager.InsertProcedureWithOutputInsertedId("CreateCategory", sqlParameters); } catch (Exception exception) { throw exception; } return category; }
public List<Category> GetAllCategories() { List<Category> categories = new List<Category>(); try { DataTable dataTable = sqlDalManager.SelectAllProcedure("GetAllCategories"); if (dataTable.Rows.Count > 0) { foreach (DataRow dataRow in dataTable.Rows) { Category category = new Category(); category.CategoryID = int.Parse(dataRow["CategoryID"].ToString()); category.CategoryName = dataRow["CategoryName"].ToString(); categories.Add(category); } } } catch (SqlException exception) { throw exception; } return categories; }
/// <summary> /// The add new category event handler. /// </summary> /// <param name="category"> /// The category. /// </param> public void AddNewCategoryEventHandler(Category category) { this.AllCategories.Add(category); }