private void btnEditCategory_Click(object sender, EventArgs e) { if (dataGridViewCategories.SelectedRows.Count > 0) { using (ShopContext context = new ShopContext()) { string categoryID = dataGridViewCategories.SelectedRows[0].Cells["CategoryId"].Value.ToString(); CategoryForm category = new CategoryForm(); category.FormCategory = context.Categories.First(x => x.CategoryId == categoryID); if (DialogResult.OK == category.ShowDialog()) { context.SaveChanges(); } } LoadCategories(); } }
private void btnAddCategory_Click(object sender, EventArgs e) { CategoryForm category = new CategoryForm(); if (DialogResult.OK == category.ShowDialog()) { using (ShopContext context = new ShopContext()) { Category newCategory = new Category() { CategoryId = category.FormCategory.CategoryId, CategoryName = category.FormCategory.CategoryName, ShopId = category.FormCategory.ShopId }; context.Categories.Add(newCategory); context.SaveChanges(); } LoadCategories(); } }