//method to delete a category public void deleteCategory(String id) { if (MessageBox.Show("Are you sure to Delete this record?", "Delete Category", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (DBEntities db = new DBEntities()) { //getting the object whichh need to be deleted vehicategory = db.VehicleCategories.Where(fc => fc.vehicleCategoryID == id).First(); //delete the object db.VehicleCategories.Remove(vehicategory); try { db.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var entityValidationErrors in ex.EntityValidationErrors) { foreach (var validationError in entityValidationErrors.ValidationErrors) { MessageBox.Show("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); } } } } MessageBox.Show("Category Removed Successfully!!!"); } //refreshing...... clearCatgoryList(); loadFoodCategories(); }//end of delete category method *******************
}//************************** //method to edit category details public void editcategory(String id) { //retreiving selected row using (DBEntities db = new DBEntities()) { //setting status to update status = "update"; btnSave.Text = "Update"; vCategory = db.VehicleCategories.Where(x => x.vehicleCategoryID == id).FirstOrDefault(); MessageBox.Show(vCategory.vehicleCategoryID); //storing values to the textboxes txtCategoryID.Text = vCategory.vehicleCategoryID; txtCategoryName.Text = vCategory.name; txtCategoryDescription.Text = vCategory.description; } }//end of edit item category method