public IActionResult ShowAppointmentsByPatientPersonalID([FromQuery] string personalID) { PatientShowAppointments response = repository.ShowPatientAppointmentsByPersonalID(personalID); if (response != null) { return(new ObjectResult(response)); } else { return(new NotFoundObjectResult("A user by that personal ID was not found or there aren't any appointments of that user")); } }
public PatientShowAppointments ShowPatientAppointmentsByPersonalID(string personalID) { StoreContext db = new StoreContext(); PatientShowAppointments response = new PatientShowAppointments(); Patient patient = db.Patient .Where(s => s.Idnumber == personalID) .Include(u => u.User) .Include(b => b.BloodType) .Include(s => s.Status) .FirstOrDefault(); if (patient != null) { response.Patient = mapper.Map <PatientDTO>(patient); List <AppointmentDetails> appointments = db.AppointmentDetails .Where(p => p.PatientId == patient.PatientId) .Include(a => a.Appointment) .Include(p => p.Patient) .ThenInclude(u => u.User) .Include(u => u.Appointment) .ThenInclude(d => d.Doctor) .Include(u => u.Appointment) .ThenInclude(c => c.CreatedBy) .Include(u => u.Appointment) .ThenInclude(s => s.Status) .ToList(); if (appointments != null) { response.Appointments = mapper.Map <List <PatientAppointmentsDTO> >(appointments); return(response); } else { return(null); } } else { return(null); } }