public async Task <IActionResult> Create([Bind("RouteID,LineID,BuggyID")] RouteModel routeModel) { if (ModelState.IsValid) { _context.Add(routeModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BuggyID"] = new SelectList(_context.Buggies, "BuggyID", "BuggyID", routeModel.BuggyID); ViewData["LineID"] = new SelectList(_context.Lines, "ID", "ID", routeModel.LineID); return(View(routeModel)); }
public ActionResult Create(Machine machine, int EngineerId) { _db.Add(machine); if (EngineerId != 0) { _db.MachineEngineer.Add(new MachineEngineer() { EngineerId = EngineerId, MachineId = machine.MachineId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Name")] LineModel lineModel) { try { if (ModelState.IsValid) { _context.Add(lineModel); 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."); } return(View(lineModel)); }