public ActionResult RequestAppointment(int id) { var model = new DoctorPatientAppointment(); model.DoctorId = id; var user = UserManager.FindById(User.Identity.GetUserId()); Patient patient = db.Patients.Where(z => z.Embg.Equals(user.Embg)).FirstOrDefault(); model.PatientId = patient.Id; return(View(model)); }
public ActionResult RequestAppointment(DoctorPatientAppointment model) { if (ModelState.IsValid) { Appointment appointment = new Appointment(); appointment.Date = model.Date; appointment.FirstName = model.FirstName; appointment.LastName = model.LastName; appointment.Condition = model.Condition; appointment.Age = model.Age; var patient = db.Patients.Where(z => z.Id.Equals(model.PatientId)).FirstOrDefault(); var doctor = db.Doctors.Where(z => z.Id.Equals(model.DoctorId)).FirstOrDefault(); appointment.patient = patient; appointment.doctor = doctor; db.Appointments.Add(appointment); db.SaveChanges(); return(RedirectToAction("ShowAppointmentsPatient")); } return(View(model)); }