예제 #1
0
        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"));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
 public void addNewItem(Item newItem)
 {
     _context.Add(newItem);
     _context.SaveChanges();
 }