public IActionResult GetClinicians(SearchDoctorModel search) { var provider_category = _providerCategoryService.GetClinicianCategory(); var areas = Options.Getlookups("area_of_interest"); var clinicians = _clinicianService.GetClinicians(); List <DoctorModel> doctorModels = new List <DoctorModel>(); if (search.appointmentType.HasValue) { provider_category = provider_category.Where(e => e.appointment_type == search.appointmentType.Value); } if (search.appointmentCategory.HasValue) { provider_category = provider_category.Where(e => e.appointment_category == search.appointmentCategory.Value); } if (search.appointmentActivity.HasValue) { provider_category = provider_category.Where(e => e.appointment_category_sub == search.appointmentActivity.Value); } if (provider_category.Any()) { var ids = provider_category.Select(e => e.clinician_id).ToList(); clinicians = clinicians.Where(e => ids.Contains(e.id)); } //check if name is one of the search models if (!string.IsNullOrEmpty(search.name)) { var category = areas.FirstOrDefault(x => x.value.ToLower() == search.name.ToLower()); clinicians = clinicians.Where(e => e.last_name.ToLower().Contains(search.name.ToLower()) || e.first_name.ToLower().Contains(search.name.ToLower()) || (e.area_of_interest == (category == null ? -1 : category.id))); } if (clinicians.Count() > 0) { foreach (var clinician in clinicians) { doctorModels.Add(new DoctorModel(clinician)); } } return(Ok(doctorModels)); }