public async Task <IActionResult> Edit(int id, [Bind("DoctorId,Unavailable,UnavailabilityId")] DoctorUnavailability doctorUnavailability) { if (id != doctorUnavailability.UnavailabilityId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(doctorUnavailability); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DoctorUnavailabilityExists(doctorUnavailability.UnavailabilityId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DoctorId"] = new SelectList(_context.Doctor, "DoctorId", "DoctorEmail", doctorUnavailability.DoctorId); return(View(doctorUnavailability)); }
public async Task <IActionResult> Create([Bind("ApptId,ApptDate,AppointmentReason,PatientEmail,PatientId,VisitRecord,DoctorId")] Appointment appointment) { if (ModelState.IsValid) { _context.Add(appointment); await _context.SaveChangesAsync(); Console.WriteLine("The appointment tiem is " + appointment.ApptDate); //Remove from available time var appointment_context = _context.DoctorAvailability.Where(a => a.AvailableTime == appointment.ApptDate && a.DoctorId == appointment.DoctorId).FirstOrDefault(); _context.DoctorAvailability.Remove(appointment_context); await _context.SaveChangesAsync(); //Add to unavailable time var addtime = new DoctorUnavailability { DoctorId = appointment.DoctorId, Unavailable = appointment.ApptDate }; _context.DoctorUnavailability.Add(addtime); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DoctorId"] = new SelectList(_context.Doctor, "DoctorId", "DoctorEmail", appointment.DoctorId); ViewData["PatientId"] = new SelectList(_context.Patient, "PatientId", "PatientEmail", appointment.PatientId); return(View(appointment)); }
public async Task <IActionResult> Create([Bind("DoctorId,Unavailable,UnavailabilityId")] DoctorUnavailability doctorUnavailability) { if (ModelState.IsValid) { _context.Add(doctorUnavailability); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DoctorId"] = new SelectList(_context.Doctor, "DoctorId", "DoctorEmail", doctorUnavailability.DoctorId); return(View(doctorUnavailability)); }
public async Task <IActionResult> Create([Bind("ApptId,ApptDate,AppointmentReason,PatientEmail,PatientId,VisitRecord,DoctorId")] Appointment appointment) { if (ModelState.IsValid) { var findbyemail = _context.Appointment.Where(c => c.PatientEmail == User.Identity.Name).Count(); //If the email is found, reject creating the appointment and redirect to the page that says unsuccessful if (findbyemail != 0) { return(View("AppointmentExists")); } //Add the user to misused user database if (User.IsInRole("Patient")) { if (!UserExists(User.Identity.Name)) { var newuser = new MisusedUser { UserEmail = User.Identity.Name, Misusedcount = 0 }; _context.MisusedUser.Add(newuser); await _context.SaveChangesAsync(); } } _context.Add(appointment); await _context.SaveChangesAsync(); //Remove from available time var appointment_context = _context.DoctorAvailability.Where(a => a.AvailableTime == appointment.ApptDate && a.DoctorId == appointment.DoctorId).FirstOrDefault(); _context.DoctorAvailability.Remove(appointment_context); await _context.SaveChangesAsync(); //Add to unavailable time var addtime = new DoctorUnavailability { DoctorId = appointment.DoctorId, Unavailable = appointment.ApptDate }; _context.DoctorUnavailability.Add(addtime); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DoctorId"] = new SelectList(_context.Doctor, "DoctorId", "DoctorName", appointment.DoctorId); ViewData["PatientId"] = new SelectList(_context.Patient, "PatientId", "PatientEmail", appointment.PatientId); return(View(appointment)); }