public async Task <IActionResult> Edit(int id, [Bind("ID,AspNetUserId,FirstName,LastName,Username,Password,DOB,UTSID,History,Role")] User user) { if (id != user.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Notes,Location,Time,DoctorID,PatientID")] Appointment appointment) { //Handle No Doctor Preference if (appointment.DoctorID == -1) { var busyDoctors = from s in _context.Appointments where s.Time == appointment.Time select s.DoctorID; var freeDoctors = from d in _context.Users where d.Role == "Doctor" && busyDoctors.All(b => b != d.ID) select d.ID; if (freeDoctors.Count() != 0) { appointment.DoctorID = freeDoctors.First(); } } if (id != appointment.ID) { return(NotFound()); } //appointment.ID = id; 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["PatientID"] = new SelectList(_context.Users, "ID", "ID", appointment.PatientID); return(View(appointment)); }