예제 #1
0
        public async Task <IActionResult> Get([FromRoute] int id, [FromQuery] string search = null)
        {
            //check if logged in as dr, if not, then return not authorized
            //get all the patients of the currently logged in doctor.


            if (await _clinicRepository.GetDoctorPatientsAsync(id) is IEnumerable <Patient> patients)
            {
                if (search is not null)
                {
                    //filter by name based on search string
                    var searchPatient = patients.FirstOrDefault(p => p.Name.ToLower() == search.ToLower());

                    return(Ok(searchPatient));
                }
                else
                {
                    return(Ok(patients));
                }
            }
            else
            {
                return(NotFound());
            }
        }