//While adding products here, we did not control what we did in other forms. //Because there may be many products with the same name, with different brands and different categories. private void buttonAddProduct_Click(object sender, EventArgs e) { Product newProduct = new Product(); if (string.IsNullOrEmpty(textBoxNameProduct.Text)) { MessageBox.Show("ÜRÜN İSMİ BOŞ BIRAKILAMAZ!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { newProduct.ImageAdress = textBoxImageAddressProduct.Text; newProduct.Name = textBoxNameProduct.Text; newProduct.Rating = (double)Convert.ToDecimal(textBoxRatingProduct.Text); newProduct.Price = Convert.ToDecimal(textBoxPriceProduct.Text); newProduct.Discount = (double)Convert.ToDecimal(textBoxdiscountProduct.Text); newProduct.ProductInfos = textBoxInfoProduct.Text; newProduct.CategoryId = (int)Convert.ToDecimal(textBoxProductCategoryId.Text); newProduct.BrandsId = (int)Convert.ToDecimal(textBoxProductBrandId.Text); db.Product.Add(newProduct); int affectedRow = db.SaveChanges(); if (affectedRow > 0) { MessageBox.Show("ÜRÜN EKLENMESİ BAŞARILI!"); getProducts(); } else { MessageBox.Show("ÜRÜN EKLENMESİ BAŞARISIZ...", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void buttonAddProduct_Click(object sender, EventArgs e) { Product newProduct = new Product(); newProduct.ImageAdress = textBoxImageAdress.Text; newProduct.Name = textBoxProductName.Text; newProduct.Description = textBoxProductDescription.Text; newProduct.Rating = Convert.ToDouble(textBoxProductRating.Text); newProduct.Price = Convert.ToDecimal(textBoxProductPrice.Text); newProduct.Discount = Convert.ToDouble(textBoxProductDiscount.Text); newProduct.ProductInfos = textBoxProductInfos.Text; productBusiness.Add(newProduct); int affectedRow = dbContext.SaveChanges(); if (affectedRow > 0) { MessageBox.Show("başarılı"); getProducts(); } else { MessageBox.Show("olmadı"); } }
private void buttonAddBrand_Click(object sender, EventArgs e) { Brand newBrand = new Brand(); if (string.IsNullOrEmpty(textBoxBrandName.Text)) { MessageBox.Show("MARKANIN İSMİ BOŞ BIRAKILAMAZ!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //This method compares the brand name taken from the textBox with the brand names in the database. //If you already have a brand name, it will prevent you from adding another. var IsBrandExist = db.Brands.Where(x => x.Name == textBoxBrandName.Text).FirstOrDefault(); if (IsBrandExist != null) { MessageBox.Show("BU MARKA MEVCUT BU NEDENLE EKLENEMEZ!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { newBrand.Name = textBoxBrandName.Text; db.Brands.Add(newBrand); int affectedRow = db.SaveChanges(); if (affectedRow > 0) { MessageBox.Show("MARKA EKLENMESİ BAŞARILI!"); getBrands(); } else { MessageBox.Show("MARKA EKLENMESİ BAŞARISIZ...", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void buttonAddCategory_Click(object sender, EventArgs e) { Category newCategory = new Category(); if (string.IsNullOrEmpty(textBoxCategoryName.Text)) { MessageBox.Show("KATEGORİ İSMİ BOŞ BIRAKILAMAZ!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //This method compares the category name taken from the textBox with the category names in the database. //If you already have a category name, it will prevent you from adding another. var IsCategoryExist = db.Categories.Where(x => x.Name == textBoxCategoryName.Text).FirstOrDefault(); if (IsCategoryExist != null) { MessageBox.Show("BU KATEGORİ MEVCUT BU NEDENLE EKLENEMEZ!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { newCategory.Name = textBoxCategoryName.Text; newCategory.Description = textBoxCategoryDescription.Text; db.Categories.Add(newCategory); int affectedRow = db.SaveChanges(); if (affectedRow > 0) { MessageBox.Show("KATEGORİ EKLENMESİ BAŞARILI!"); getCategories(); } else { MessageBox.Show("KATEGORİ EKLENMESİ BAŞARISIZ...", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public void Add(Product product) { dbContext.Products.Add(product); dbContext.SaveChanges(); }
public void Add(Category category) { db.Categories.Add(category); db.SaveChanges(); }
public void Add(Brand brand) { db.Brands.Add(brand); db.SaveChanges(); }
public void Add(Product product) { db.Product.Add(product); db.SaveChanges(); }