public async Task <IActionResult> Create([Bind("DepartmentID,Name")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Create( [Bind("DepartmentID,LastName,FirstMidName,Address,City,State,Zip")] Employee employee) { try { if (ModelState.IsValid) { _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException ex) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } PopulateDepartmentsDropDownList(employee); return(View(employee)); }