public void OnGet(string SearchTerms, uint?CalorieMin, uint?CalorieMax, double?PriceMin, double?PriceMax, string[] ItemTypes) { this.SearchTerms = SearchTerms; this.CalorieMin = CalorieMin; this.CalorieMax = CalorieMax; this.PriceMin = PriceMin; this.PriceMax = PriceMax; this.ItemTypes = ItemTypes; FilteredMenu = Menu.All(); if (SearchTerms != null) { FilteredMenu = FilteredMenu.Where(menuItem => menuItem.Name.Contains(SearchTerms, StringComparison.InvariantCultureIgnoreCase)); } if (CalorieMin != null) { FilteredMenu = FilteredMenu.Where(menuItem => menuItem.Calories != null && menuItem.Calories >= CalorieMin); } if (CalorieMax != null) { FilteredMenu = FilteredMenu.Where(menuItem => menuItem.Calories != null && menuItem.Calories <= CalorieMax); } if (PriceMin != null) { FilteredMenu = FilteredMenu.Where(menuItem => menuItem.Price >= PriceMin); } if (PriceMax != null) { FilteredMenu = FilteredMenu.Where(menuItem => menuItem.Price <= PriceMax); } if (ItemTypes != null && ItemTypes.Length != 0) { List <IOrderItem> tempList = new List <IOrderItem>(); // This part is a bit messy // If Entree is not selected, we remove every entree from the list. // This is done because I couldn't find a way to remove things from the list based on type otherwise if (!ItemTypes.Contains("Entree")) { FilteredMenu = FilteredMenu.Where(menuItem => !Menu.Entrees.Contains(menuItem)); } // And the same for Drinks if (!ItemTypes.Contains("Drink")) { FilteredMenu = FilteredMenu.Where(menuItem => !Menu.Drinks.Contains(menuItem)); } // And again for Sides if (!ItemTypes.Contains("Side")) { FilteredMenu = FilteredMenu.Where(menuItem => !Menu.Sides.Contains(menuItem)); } } }
public void OnGet(string SearchTerms, int?CaloriesMin, int?CaloriesMax, double?PriceMin, double?PriceMax) { this.SearchTerms = SearchTerms; FilteredMenu = Menu.All; if (SearchTerms != null) { FilteredMenu = FilteredMenu.Where(item => item.ToString().Contains(SearchTerms)); } if (Request.Query["Catagories"].Count != 0) { Category = Request.Query["Catagories"]; //FilteredMenu = Menu.FilterByCategory(FilteredMenu, Category); if (!Category.Contains("entree")) { FilteredMenu = FilteredMenu.Where(item => !(item is Entree)); } if (!Category.Contains("side")) { FilteredMenu = FilteredMenu.Where(item => !(item is Side)); } if (!Category.Contains("drink")) { FilteredMenu = FilteredMenu.Where(item => !(item is Drink)); } } //FilteredMenu = Menu.FilterByCalories(FilteredMenu, CaloriesMin, CaloriesMax); this.CaloriesMin = CaloriesMin; this.CaloriesMax = CaloriesMax; if (CaloriesMin != null) { FilteredMenu = FilteredMenu.Where(item => item.Calories >= CaloriesMin); } if (CaloriesMax != null) { FilteredMenu = FilteredMenu.Where(item => item.Calories <= CaloriesMax); } //FilteredMenu = Menu.FilterByPrice(FilteredMenu, PriceMin, PriceMax); this.PriceMin = PriceMin; this.PriceMax = PriceMax; if (PriceMin != null) { FilteredMenu = FilteredMenu.Where(item => item.Price >= PriceMin); } if (PriceMax != null) { FilteredMenu = FilteredMenu.Where(item => item.Price <= PriceMax); } }