private async Task <IEnumerable <MealSearchResultV2> > GetMealSearchResults(SearchMealsByDistance mealByDistance) { double lat = 0; double lng = 0; _externalService.GeocodeLocation(mealByDistance, out lat, out lng); IEnumerable <MealSearchResultV2> searchedMeals = null; if (mealByDistance.MealName != null) { mealByDistance.Meals = _externalService.SearchMealsList(lat, lng, mealByDistance.Distance); if (mealByDistance.Price == null || !mealByDistance.Price.HasValue) { searchedMeals = mealByDistance.Meals.Where(meal => meal.Title.Contains(mealByDistance.MealName)).OrderBy(x => x.Distance); } else { searchedMeals = mealByDistance.Meals.Where(meal => meal.Title.Contains(mealByDistance.MealName) && meal.Price != null && meal.Price <= mealByDistance.Price).OrderBy(x => x.Distance); } } else if (mealByDistance.Cuisine != null) { mealByDistance.Meals = _externalService.SearchMealsByCuisineList(lat, lng, mealByDistance.Distance, mealByDistance.CuisineId); if (mealByDistance.Price == null || !mealByDistance.Price.HasValue) { searchedMeals = mealByDistance.Meals.OrderBy(x => x.Distance); } else { searchedMeals = mealByDistance.Meals.Where(meal => meal.Price <= mealByDistance.Price).OrderBy(x => x.Distance); } } return(searchedMeals); }