public async Task <IActionResult> Create([Bind("Id,Name,Value,CategoryId")] InsuredItem insuredItem) { if (ModelState.IsValid || insuredItem.Value >= 0) // reject if user puts in zero or negative value { _context.Add(insuredItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } SetViewBag(); return(View(insuredItem)); }
public async Task <IActionResult> Create([Bind("Id,Name,Value,CategoryId")] InsuredItem insuredItem) { // if valid form if (ModelState.IsValid && insuredItem.Value >= 0) // reject if user puts in zero or negative value { _context.Add(insuredItem); //adds to the context await _context.SaveChangesAsync(); // commit changes to db. return(RedirectToAction(nameof(Index))); // return listing } SetViewBag(); return(RedirectToAction(nameof(Index))); }