internal bool AddCategory(string Name) { var newCategory = new Category(); newCategory.CategoryName = Name; using (ProductContext _db = new ProductContext()) { // Add product to DB. _db.Categories.Add(newCategory); _db.SaveChanges(); } return true; }
protected void gvCategories_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName != "Page" && e.CommandName != "Sort") { GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer; int rowIndex = gvr.RowIndex; Category c = new Category(); c = categoryAction.GetCategory(int.Parse(gvCategories.Rows[rowIndex].Cells[0].Text)); if (e.CommandName == "edt") { lblEditCatIDDisplay.Text = c.CategoryID.ToString(); txtEditCatName.Text = c.CategoryName.ToString(); ManageEditCatValidation(true); ModalEditCategory.Show(); } else if (e.CommandName == "dlt") { lblDeleteCatName.Text = c.CategoryName.ToString(); lblDeleteCatID.Text = c.CategoryID.ToString(); ModalDeleteCategory.Show(); } } }