public async Task <IActionResult> Edit(int id) { var employeeToUpdate = await _context.Employees .FirstOrDefaultAsync(m => m.ID == id); if (await TryUpdateModelAsync <Employee>(employeeToUpdate, "", c => c.FirstName, c => c.LastName, c => c.Phone, c => c.FavouriteIceCream)) { try { _context.Update(employeeToUpdate); await _context.SaveChangesAsync(); UpdateUserNameCookie(employeeToUpdate.FullName); return(RedirectToAction(nameof(Details))); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employeeToUpdate.ID)) { return(NotFound()); } else { ModelState.AddModelError("", "Unable to save changes. The record you attempted to edit " + "was modified by another user after you received your values. You need to go back and try your edit again."); } } catch (DbUpdateException) { ModelState.AddModelError("", "Something went wrong in the database."); } } return(View(employeeToUpdate)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,TrialName")] MedicalTrial medicalTrial) { if (id != medicalTrial.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(medicalTrial); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MedicalTrialExists(medicalTrial.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(medicalTrial)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Notes,appDate,extraFee,PatientID,ApptReasonID")] Appointment appointment) { if (id != appointment.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(appointment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppointmentExists(appointment.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ApptReasonID"] = new SelectList(_context.ApptReasons, "ID", "ReasonName", appointment.ApptReasonID); ViewData["PatientID"] = new SelectList(_context.Patients, "ID", "FirstName", appointment.PatientID); return(View(appointment)); }
public async Task <IActionResult> Update(int id) { var appointmentToUpdate = await _context.Appointments .Include(a => a.ApptReason) .Include(a => a.Patient) .FirstOrDefaultAsync(m => m.ID == id); //Check that you got it or exit with a not found error if (appointmentToUpdate == null) { return(NotFound()); } //Get the URL with the last filter, sort and page parameters ViewData["returnURL"] = MaintainURL.ReturnURL(HttpContext, "PatientAppt"); //Try updating it with the values posted if (await TryUpdateModelAsync <Appointment>(appointmentToUpdate, "", p => p.Notes, p => p.appDate, p => p.extraFee, p => p.ApptReasonID)) { try { _context.Update(appointmentToUpdate); await _context.SaveChangesAsync(); return(Redirect(ViewData["returnURL"].ToString())); } catch (DbUpdateConcurrencyException) { if (!AppointmentExists(appointmentToUpdate.ID)) { return(NotFound()); } else { throw; } } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } } PopulateDropDownLists(appointmentToUpdate); return(View(appointmentToUpdate)); }