public IActionResult createprod(Product newproduct) { List <Product> ReturnValues = _context.Products.Where(p => p.ProdName.Equals(newproduct.ProdName)).ToList(); foreach (var products in ReturnValues) { if (products.ProdName == newproduct.ProdName) { TempData["updatemsg"] = "Product already exists - no update feature yet"; return(RedirectToAction("Products")); } } _context.Add(newproduct); _context.SaveChanges(); return(RedirectToAction("Products")); }
public async Task <IActionResult> Create([Bind("ID,Name,Price,Unit,ExpiryDate")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description,Price")] Product product) { if (ModelState.IsValid) { product.Id = Guid.NewGuid(); _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public void addNewItem(Item newItem) { _context.Add(newItem); _context.SaveChanges(); }