Ejemplo n.º 1
0
        public async Task <Doctor> GetDoctor(int id)
        {
            ExceptionThrowers.ThrowErrorIfNotValidId(id);

            var doctor = await _context.Doctors.Include(d => d.PatientDoctors)
                         .ThenInclude(d => d.Patient)
                         .FirstOrDefaultAsync(d => d.Id == id);

            if (doctor == null)
            {
                throw new NotFoundException("Doctor not found");
            }


            return(doctor);
        }
Ejemplo n.º 2
0
        public async Task <Patient> GetPatient(int id, bool?withRecords = false)
        {
            ExceptionThrowers.ThrowErrorIfNotValidId(id);

            Patient patient;

            if (withRecords == true)
            {
                patient = await _context.Patients.Include(p => p.Records).FirstOrDefaultAsync(p => p.Id == id);
            }
            else
            {
                patient = await _context.Patients.FindAsync(id);
            }

            if (patient == null)
            {
                throw new BadRequestException("Patient not found");
            }


            return(patient);
        }