示例#1
0
        private void productsGridView_RowLeave(object sender, DataGridViewCellEventArgs e)
        {
            Product productToAdd = (Product)productsGridView.Rows[e.RowIndex]?.DataBoundItem;

            if (productToAdd != null && selectedCategory != null)
            {
                productToAdd.CategoryId = selectedCategory.CategoryId;
                context.Products.Add(productToAdd);
                context.SaveChanges();
                productsGridView.Refresh();
            }
        }
示例#2
0
        private void registerTile_Click(object sender, EventArgs e)
        {
            var customerToRegister = new Customer()
            {
                CompanyName = companyNameTextBox.Text.Trim(),
                Password    = passwordTextBox.Text
            };

            using (var ctx = new ProdContext())
            {
                var nameAvailable = ctx.Customers.Where(c => c.CompanyName == customerToRegister.CompanyName).Count() == 0;

                if (nameAvailable)
                {
                    ctx.Customers.Add(customerToRegister);
                    ctx.SaveChanges();

                    this.Hide();
                    new DashboardForm().ShowDialog();
                    this.Close();
                }
                else
                {
                    showInvalidCredentialsMessageBox("Company name is already taken.");
                }
            }
        }
 static void AddNewCategory_Console()
 {
     using (var ctx = new ProdContext())
     {
         Console.WriteLine("Provide new category name:");
         Category category = new Category
         {
             Name = Console.ReadLine()
         };
         ctx.Categories.Add(category);
         ctx.SaveChanges();
     }
 }