public static List <Drink> Search(string name, List <string> ingredients, List <string> alcoholTypes, List <string> categories) { IQueryable <Drink> query = DrinkList.AsQueryable <Drink>(); if (!string.IsNullOrWhiteSpace(name)) { query = query.Where(p => p.Name.ToUpper().Contains(name.ToUpper())); } if (ingredients.Count() > 0) { query = query.Where(p => p.Ingredients.Any(x => ingredients.Contains(x.IngredientName))); } if (alcoholTypes.Count() > 0) { query = query.Where(p => alcoholTypes.Contains(p.Alcohol)); } if (categories.Count() > 0) { query = query.Where(p => categories.Contains(p.Category)); } return(query.ToList()); }
public static List <Drink> SearchByAvailableIngredients(List <string> ingredients) { IQueryable <Drink> query = DrinkList.AsQueryable <Drink>(); query = query.Where(p => p.Ingredients.All(x => ingredients.Contains(x.IngredientName) || x.IsOptionalIngredient())); return(query.ToList()); //query = query.Where(p => p.Ingredients.Except()) //query = query.Where(p => ingredients.Intersect(p.Ingredients).count) }