Exemple #1
0
        private void btnEditItem_Click(object sender, EventArgs e)
        {
            if (dataGridViewItems.SelectedRows.Count > 0)
            {
                using (ShopContext context = new ShopContext())
                {
                    string itemID = dataGridViewItems.SelectedRows[0].Cells["ItemId"].Value.ToString();

                    ItemForm item = new ItemForm();
                    item.FormItem = context.Items.First(x => x.ItemId == itemID);
                    if (DialogResult.OK == item.ShowDialog())
                    {
                        context.SaveChanges();
                    }
                }
                LoadItems();
            }
        }
Exemple #2
0
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            ItemForm item = new ItemForm();

            if (DialogResult.OK == item.ShowDialog())
            {
                using (ShopContext context = new ShopContext())
                {
                    Item newItem = new Item()
                    {
                        ItemId     = item.FormItem.ItemId,
                        ShopId     = item.FormItem.ShopId,
                        CategoryId = item.FormItem.CategoryId,
                        Name       = item.FormItem.Name,
                        Price      = item.FormItem.Price
                    };
                    context.Items.Add(newItem);

                    context.SaveChanges();
                }
                LoadItems();
            }
        }