示例#1
0
        private void addCategory_Click(object sender, EventArgs e)
        {
            CategoriesEditor editor = new CategoriesEditor();

            editor.ButtonName = "ADD CATEGORY";
            if (editor.ShowDialog() == DialogResult.OK)
            {
                db.Categories.Add(new Categories()
                {
                    Name = editor.CategoryName
                });
                db.SaveChanges();
                MessageBox.Show("Category succesfully added", "Message",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                LoadCategories();
            }
        }
示例#2
0
        private void delCategory_Click(object sender, EventArgs e)
        {
            CategoriesEditor editor = new CategoriesEditor();

            editor.ButtonName = "DELETE CATEGORY";
            if (editor.ShowDialog() == DialogResult.OK)
            {
                var category = db.Categories.Where(c => c.Name == editor.CategoryName).FirstOrDefault();
                if (category != null)
                {
                    db.Categories.Remove(category);
                    db.SaveChanges();
                    MessageBox.Show("Category succesfully deleted", "Message",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadCategories();
                }
            }
        }