public async Task <IActionResult> Edit(int id, [Bind("MachineMaintenanceId,MachineId,MaintenanceId,MaintenanceTime,MaintenanceCost")] MachineMaintenance machineMaintenance) { if (id != machineMaintenance.MachineMaintenanceId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(machineMaintenance); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MachineMaintenanceExists(machineMaintenance.MachineMaintenanceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["MachineId"] = new SelectList(_context.Machines, "MachineId", "MachineName", machineMaintenance.MachineId); ViewData["MaintenanceId"] = new SelectList(_context.Maintenances, "MaintenanceId", "MaintenanceType", machineMaintenance.MaintenanceId); return(View(machineMaintenance)); }
public async Task <IActionResult> Create(int?id, [Bind("MachineMaintenanceId,MachineId,MaintenanceId,MaintenanceTime,MaintenanceCost")] MachineMaintenance machineMaintenance) { if (ModelState.IsValid) { if (id.HasValue) { machineMaintenance.MachineId = id.Value; } _context.Add(machineMaintenance); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Machines", new { id })); } if (id == null) { ViewData["MachineId"] = new SelectList(_context.Machines, "MachineId", "MachineName", machineMaintenance.MachineId); } else { ViewData["MachineId"] = id; } ViewData["MaintenanceId"] = new SelectList(_context.Maintenances, "MaintenanceId", "MaintenanceType", machineMaintenance.MaintenanceId); return(PartialView(machineMaintenance)); }