private void addNewProductToolStripMenuItem_Click(object sender, EventArgs e) { NewProductForm newProductform = new NewProductForm(ref m_register); DialogResult tempDR = newProductform.ShowDialog(); Product toAdd; if (tempDR != DialogResult.OK) { return; } toAdd = newProductform.ProductToAdd; m_register.Products.Add(toAdd); foreach (Control c in m_inventoryTab.Controls) { if (c is InventoryControl) { InventoryControl inv = c as InventoryControl; inv.UpdateInventory(); } } m_register.Save(); }
public IActionResult Products() { NewProductForm newProduct = new NewProductForm(); newProduct.CurrentProducts = dbContext.Products.ToList(); return(View(newProduct)); }
public IActionResult NewProduct(NewProductForm returnProduct) { if ((!ModelState.IsValid) || ((ModelState.IsValid) && (((dbContext.Products.Any(u => u.Name == returnProduct.Name)) || (returnProduct.Price <= 0))))) { if (returnProduct.Price <= 0) { ModelState.AddModelError("Price", "You can not set product price less or equal 0"); } if (dbContext.Products.Any(u => u.Name == returnProduct.Name)) { ModelState.AddModelError("Name", "Product already existed!"); } NewProductForm newProduct = new NewProductForm(); newProduct.CurrentProducts = dbContext.Products.ToList(); return(View("Products", newProduct)); } else { Product newproduct = new Product(); newproduct.Name = returnProduct.Name; newproduct.Price = returnProduct.Price; newproduct.Description = returnProduct.Description; dbContext.Products.Add(newproduct); dbContext.SaveChanges(); return(Redirect("/products")); } }
// Opens menu to add a new product to the catalog. private void nieuwObjectToolStripMenuItem_Click(object sender, EventArgs e) { NewProductForm nof = new NewProductForm(catalogPanel1); nof.ShowDialog(); }