Skip to content

Commit

Permalink
Website Milestone 2 Complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertOstermann committed Nov 22, 2019
1 parent ab15bd5 commit 422d033
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 60 deletions.
100 changes: 59 additions & 41 deletions Menu/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Menu
/// <summary>
/// Gets a list of available menu items.
/// </summary>
public List<object> AvailableMenuItems
public List<IMenuItem> AvailableMenuItems
{
get
{
Expand All @@ -38,7 +38,7 @@ public List<object> AvailableMenuItems
CretaceousCombo steakosaurusCombo = new CretaceousCombo(steakosaurusBurger);
CretaceousCombo kingBurgerCombo = new CretaceousCombo(kingBurger);
CretaceousCombo velociWrapCombo = new CretaceousCombo(velociWrap);
List<object> items = new List<object>();
List<IMenuItem> items = new List<IMenuItem>();
items.Add(jurassicJava);
items.Add(sodasaurus);
items.Add(tyrannotea);
Expand Down Expand Up @@ -67,7 +67,7 @@ public List<object> AvailableMenuItems
/// <summary>
/// Gets a list of available entrees.
/// </summary>
public List<Entree> AvailableEntrees
public List<IMenuItem> AvailableEntrees
{
get
{
Expand All @@ -78,7 +78,7 @@ public List<Entree> AvailableEntrees
SteakosaurusBurger steakosaurusBurger = new SteakosaurusBurger();
TRexKingBurger kingBurger = new TRexKingBurger();
VelociWrap velociWrap = new VelociWrap();
List<Entree> items = new List<Entree>();
List<IMenuItem> items = new List<IMenuItem>();
items.Add(brontowurst);
items.Add(dinoNuggets);
items.Add(prehistoricPBJ);
Expand All @@ -92,15 +92,15 @@ public List<Entree> AvailableEntrees
/// <summary>
/// Gets a list of available sides.
/// </summary>
public List<Side> AvailableSides
public List<IMenuItem> AvailableSides
{
get
{
Fryceritops fryceritops = new Fryceritops();
MeteorMacAndCheese meteorMacAndCheese = new MeteorMacAndCheese();
MezzorellaSticks mezzorellaSticks = new MezzorellaSticks();
Triceritots triceritots = new Triceritots();
List<Side> items = new List<Side>();
List<IMenuItem> items = new List<IMenuItem>();
items.Add(fryceritops);
items.Add(meteorMacAndCheese);
items.Add(mezzorellaSticks);
Expand All @@ -111,15 +111,15 @@ public List<Side> AvailableSides
/// <summary>
/// Gets a list of available drinks.
/// </summary>
public List<Drink> AvailableDrinks
public List<IMenuItem> AvailableDrinks
{
get
{
JurassicJava jurassicJava = new JurassicJava();
Sodasaurus sodasaurus = new Sodasaurus();
Tyrannotea tyrannotea = new Tyrannotea();
Water water = new Water();
List<Drink> items = new List<Drink>();
List<IMenuItem> items = new List<IMenuItem>();
items.Add(jurassicJava);
items.Add(sodasaurus);
items.Add(tyrannotea);
Expand All @@ -130,7 +130,7 @@ public List<Drink> AvailableDrinks
/// <summary>
/// Gets a list of available combos.
/// </summary>
public List<CretaceousCombo> AvailableCombos
public List<IMenuItem> AvailableCombos
{
get
{
Expand All @@ -148,7 +148,7 @@ public List<CretaceousCombo> AvailableCombos
CretaceousCombo steakosaurusCombo = new CretaceousCombo(steakosaurusBurger);
CretaceousCombo kingBurgerCombo = new CretaceousCombo(kingBurger);
CretaceousCombo velociWrapCombo = new CretaceousCombo(velociWrap);
List<CretaceousCombo> items = new List<CretaceousCombo>();
List<IMenuItem> items = new List<IMenuItem>();
items.Add(brontowurstCombo);
items.Add(dinoNuggetsCombo);
items.Add(prehistoricCombo);
Expand Down Expand Up @@ -178,72 +178,90 @@ public HashSet<string> PossibleIngredients
}
}
/// <summary>
/// Searches the available combos.
/// Searches the menu items by a search string.
/// </summary>
/// <param name="items"></param>
/// <param name="search"></param>
/// <returns></returns>
public List<CretaceousCombo> SearchCombos(string search)
public List<IMenuItem> SearchMenuItems(List<IMenuItem> items, string search)
{
List<CretaceousCombo> combos = new List<CretaceousCombo>();
foreach(CretaceousCombo combo in AvailableCombos)
List<IMenuItem> results = new List<IMenuItem>();
foreach(IMenuItem item in items)
{
if (combo.ToString().Contains(search))
if (item.ToString().Contains(search))
{
combos.Add(combo);
results.Add(item);
}
}
return combos;
return results;
}
/// <summary>
/// Searches the available entrees.
/// Filters the menu items by price.
/// </summary>
/// <param name="search"></param>
/// <param name="items"></param>
/// <param name="min"></param>
/// <returns></returns>
public List<Entree> SearchEntrees(string search)
public List<IMenuItem> FilterByMin (List<IMenuItem> items, float min)
{
List<Entree> entrees = new List<Entree>();
foreach (Entree entree in AvailableEntrees)
List<IMenuItem> results = new List<IMenuItem>();
if (items != null)
{
if (entree.ToString().Contains(search))
foreach (IMenuItem item in items)
{
entrees.Add(entree);
if (item.Price >= min)
{
results.Add(item);
}
}
}
return entrees;
return results;
}
/// <summary>
/// Searches the available drinks.
/// Filters the menu items by price.
/// </summary>
/// <param name="search"></param>
/// <param name="items"></param>
/// <param name="min"></param>
/// <returns></returns>
public List<Drink> SearchDrinks(string search)
public List<IMenuItem> FilterByMax(List<IMenuItem> items, float max)
{
List<Drink> drinks = new List<Drink>();
foreach (Drink drink in AvailableDrinks)
List<IMenuItem> results = new List<IMenuItem>();
if (items != null)
{
if (drink.ToString().Contains(search))
foreach (IMenuItem item in items)
{
drinks.Add(drink);
if (item.Price <= max)
{
results.Add(item);
}
}
}
return drinks;
return results;
}
/// <summary>
/// Searches the available sides.
/// Filters the menu items by ingredients.
/// </summary>
/// <param name="search"></param>
/// <param name="items"></param>
/// <param name="ingredients"></param>
/// <returns></returns>
public List<Side> SearchSides(string search)
public List<IMenuItem> FilterByIngredients(List<IMenuItem> items, List<string> ingredients)
{
List<Side> sides = new List<Side>();
foreach (Side side in AvailableSides)
List<IMenuItem> results = new List<IMenuItem>();
if (items != null)
{
if (side.ToString().Contains(search))
results.AddRange(items);
foreach (IMenuItem item in items)
{
sides.Add(side);
foreach (string ingredient in ingredients)
{
if (item.Ingredients.Contains(ingredient))
{
results.Remove(item);
continue;
}
}
}
}
return sides;
return results;
}
/// <summary>
/// Displays the full menu contents.
Expand Down
31 changes: 23 additions & 8 deletions Website/Pages/Menu.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,42 @@
}
</div>
<form method="post">
<h3>Search</h3>
<h3>Search and Filter</h3>
<input type="text" name="search" value="@Model.search" />
<input type="submit" value="Search" />
<h3>Filter</h3>
<input type="submit" value="Filter" />
<input type="submit" name="filter" id="filter" value="Search And Filter" />
<h4>Menu Category</h4>
<label>
<input type="checkbox" value="Combos" name="category" checked="@Model.category.Contains("Combos")"/>
<input type="checkbox" value="Combos" name="category" checked="@Model.category.Contains("Combos")" />
Combo
</label>
<label>
<input type="checkbox" value="Entrees" name="category" checked="@Model.category.Contains("Entrees")"/>
<input type="checkbox" value="Entrees" name="category" checked="@Model.category.Contains("Entrees")" />
Entree
</label>
<label>
<input type="checkbox" value="Sides" name="category" checked="@Model.category.Contains("Sides")"/>
<input type="checkbox" value="Sides" name="category" checked="@Model.category.Contains("Sides")" />
Side
</label>
<label>
<input type="checkbox" value="Drinks" name="category" checked="@Model.category.Contains("Drinks")"/>
<input type="checkbox" value="Drinks" name="category" checked="@Model.category.Contains("Drinks")" />
Drink
</label>
<h3>Price</h3>
<label>
Minimum Price:
<input type="number" min="0" max="20" step="0.5" name="minimumPrice" id="minimum-price" value="@Model.minimumPrice" />
</label>
<label>
Maximum Price:
<input type="number" min="0" max="20" step="0.5" name="maximumPrice" id="maximum-price" value="@Model.maximumPrice" />
</label>
<h3>Exclude Ingredients</h3>
@foreach (string ingredients in Model.menu.PossibleIngredients)
{
<label>
<input type="checkbox" value="@ingredients" name="ingredients" checked="@Model.ingredients.Contains(ingredients.ToString())" />
@ingredients
</label>
}
</form>
</div>
49 changes: 38 additions & 11 deletions Website/Pages/Menu.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ public class MenuModel : PageModel
{
public Menu menu = new DinoDiner.Menu.Menu();

public List<CretaceousCombo> Combos;
public List<IMenuItem> Combos;

public List<IMenuItem> Entrees;

public List<IMenuItem> Drinks;

public List<IMenuItem> Sides;

public bool ShowCombos
{
Expand All @@ -26,8 +32,6 @@ public bool ShowCombos
}
}

public List<Entree> Entrees;

public bool ShowEntrees
{
get
Expand All @@ -40,8 +44,6 @@ public bool ShowEntrees
}
}

public List<Drink> Drinks;

public bool ShowDrinks
{
get
Expand All @@ -54,8 +56,6 @@ public bool ShowDrinks
}
}

public List<Side> Sides;

public bool ShowSides
{
get
Expand All @@ -74,6 +74,12 @@ public bool ShowSides
[BindProperty]
public List<string> category { get; set; } = new List<string>() { "Combos", "Entrees", "Drinks", "Sides" };

[BindProperty]
public float? minimumPrice { get; set; }
[BindProperty]
public float? maximumPrice { get; set; }
[BindProperty]
public List<string> ingredients { get; set; } = new List<string>();
public void OnGet()
{
Combos = menu.AvailableCombos;
Expand All @@ -89,10 +95,10 @@ public void OnPost()
Entrees = null;
Drinks = null;
Sides = null;
if (category.Contains("Combos")) Combos = menu.SearchCombos(search);
if (category.Contains("Entrees")) Entrees = menu.SearchEntrees(search);
if (category.Contains("Drinks")) Drinks = menu.SearchDrinks(search);
if (category.Contains("Sides")) Sides = menu.SearchSides(search);
if (category.Contains("Combos")) Combos = menu.SearchMenuItems(menu.AvailableCombos, search);
if (category.Contains("Entrees")) Entrees = menu.SearchMenuItems(menu.AvailableEntrees, search);
if (category.Contains("Drinks")) Drinks = menu.SearchMenuItems(menu.AvailableDrinks, search);
if (category.Contains("Sides")) Sides = menu.SearchMenuItems(menu.AvailableSides, search);
}
else
{
Expand All @@ -101,6 +107,27 @@ public void OnPost()
if (category.Contains("Drinks")) Drinks = menu.AvailableDrinks;
if (category.Contains("Sides")) Sides = menu.AvailableSides;
}
if (minimumPrice is float min)
{
Combos = menu.FilterByMin(Combos, min);
Entrees = menu.FilterByMin(Entrees, min);
Drinks = menu.FilterByMin(Drinks, min);
Sides = menu.FilterByMin(Sides, min);
}
if (maximumPrice is float max)
{
Combos = menu.FilterByMax(Combos, max);
Entrees = menu.FilterByMax(Entrees, max);
Drinks = menu.FilterByMax(Drinks, max);
Sides = menu.FilterByMax(Sides, max);
}
if (ingredients.Count > 0)
{
Combos = menu.FilterByIngredients(Combos, ingredients);
Entrees = menu.FilterByIngredients(Entrees, ingredients);
Drinks = menu.FilterByIngredients(Drinks, ingredients);
Sides = menu.FilterByIngredients(Sides, ingredients);
}
}
}
}

0 comments on commit 422d033

Please sign in to comment.