private void AllProducts_Load(object sender, EventArgs e)
        {
            using (DoeduSamEntities1 context = new DoeduSamEntities1())
            {
                var products = context.Product;
                foreach (Product product in products)
                {
                    Panel ProductCard = new Panel
                    {
                        Width       = 100,
                        Height      = 100,
                        BorderStyle = BorderStyle.FixedSingle
                    };
                    Label ProductTitle = new Label
                    {
                        Text = product.Title,
                        Top  = 25
                    };
                    Label ProductCoast = new Label
                    {
                        Text = product.Cost.ToString(),
                        Top  = 50
                    };

                    ProductTitle.Parent = ProductCard;
                    ProductCoast.Parent = ProductCard;

                    ProductCard.Parent  = AllProductsPanel;
                    ProductTitle.Click += new EventHandler(ShowProductInfo);
                }
            }
        }
 private void AddProductForm_Load(object sender, EventArgs e)
 {
     if (isCreate == false)
     {
         using (DoeduSamEntities1 context = new DoeduSamEntities1())
         {
             try
             {
                 var SelectedProduct = context.Product.First((product) => product.Title == ProdName);
                 MessageBox.Show(SelectedProduct.ID.ToString());
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Товар не найден");
             }
         }
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (ProductName.Text.Trim() == "" || ProductDescription.Text.Trim() == "")
                {
                    MessageBox.Show("Заполните все поля");
                }
                else
                {
                    using (DoeduSamEntities1 context = new DoeduSamEntities1())
                    {
                        if (isCreate)
                        {
                            Product product = new Product
                            {
                                Title          = ProductName.Text,
                                Cost           = decimal.Parse(ProductCoast.Text),
                                Description    = ProductDescription.Text,
                                MainImagePath  = "path",
                                IsActive       = isActive,
                                ManufacturerID = 1
                            };

                            context.Product.Add(product);
                            context.SaveChanges();
                        }
                        else
                        {
                            var SelectedProduct = context.Product.First((product) => product.Title == ProdName);
                        }
                    }
                    MessageBox.Show("Продукт добавлен");
                }
            } catch (Exception ex)
            {
                MessageBox.Show("Ошибка! Продукт не добавлен" + ex.ToString());
            }
        }