private void delete_Button_Click(object sender, EventArgs e)
 {
     if (products_DataGridView.SelectedCells.Count > 0)
     {
         DataGridViewRow   selectedRow     = products_DataGridView.SelectedCells[0].OwningRow;
         AssociatedProduct selectedProduct = selectedRow.DataBoundItem as AssociatedProduct;
         if (selectedProduct != null)
         {
             // 2017 Mar 23 MaxT - This is commented out to allow code to compile.  SessionInfoSet is no longer a valid property.  The AssociatedProductsForm will need to be adapted to new data schema for PR 41116
             //if (selectedProduct.SessionInfoSet.Count > 0)// || selectedProduct.EnterpriseScenarios.Count > 0)
             //{
             //    MessageBox.Show("This product/solution could not be deleted because it is in use by one or more sessions/scenarios.",
             //        "Delete",
             //        MessageBoxButtons.OK,
             //        MessageBoxIcon.Error
             //    );
             //}
             //else
             //{
             //    _products.Remove(selectedProduct);
             //    _context.AssociatedProducts.DeleteObject(selectedProduct);
             //}
         }
     }
 }
        private void deleteProduct_Button_Click(object sender, EventArgs e)
        {
            string vendor = vendor_TextBox.Text;
            string name   = name_TextBox.Text;


            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var temp = context.AssociatedProducts.Where(y => y.AssociatedProductId == _selectedProductId);
                if (temp.Count() == 0)
                {
                    MessageBox.Show("Name and Vendor don't exist in the database to delete", "Product Delete Error", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    AssociatedProduct del = temp.First();
                    context.DeleteObject(del);

                    context.SaveChanges();

                    LoadPage();
                }

                if (context.AssociatedProducts.Count() == 0)
                {
                    editProduct_Button.Enabled = false;
                }
            }
            deleteProduct_Button.Enabled = false;
        }
        private void editProduct_Button_Click(object sender, EventArgs e)
        {
            string vendor = vendor_TextBox.Text;
            string name   = name_TextBox.Text;

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(vendor))
            {
                MessageBox.Show("Name and Vendor Fields can not be blank", "Edit Product Error", MessageBoxButtons.OK);
                return;
            }

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var temp = context.AssociatedProducts.Where(y => y.AssociatedProductId == _selectedProductId);
                if (temp.Count() == 0)
                {
                    MessageBox.Show("Name and Vendor don't exist in the database to edit", "Product Add Error", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    AssociatedProduct edit = temp.First();
                    edit.Name   = name;
                    edit.Vendor = vendor;

                    context.SaveChanges();


                    LoadPage();
                }
            }
        }
        private void add_Button_Click(object sender, EventArgs e)
        {
            AssociatedProduct newProduct = AssociatedProduct.CreateAssociatedProduct(
                associatedProductId: SequentialGuid.NewGuid(),
                name: "New Product"
                );

            _products.Add(newProduct);
            _context.AssociatedProducts.AddObject(newProduct);
        }
        private void addProduct_button_Click(object sender, EventArgs e)
        {
            string vendor = vendor_TextBox.Text;
            string name   = name_TextBox.Text;

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(vendor))
            {
                MessageBox.Show("Name and Vendor Fields can not be blank", "Product Add Error", MessageBoxButtons.OK);
                return;
            }

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                var temp = context.AssociatedProducts.Where(y => y.Name == name && y.Vendor == vendor);
                if (temp.Count() > 0)
                {
                    MessageBox.Show("Name and Vendor already exists in the database", "Product Add Error", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    Guid id = SequentialGuid.NewGuid();

                    AssociatedProduct newProd = new AssociatedProduct();
                    newProd.AssociatedProductId = id;
                    newProd.Name   = name;
                    newProd.Vendor = vendor;

                    context.AssociatedProducts.AddObject(newProd);

                    context.SaveChanges();

                    LoadPage();
                }
            }
        }