Skip to content

Commit e0cc0ed

Browse files
committed
Start on Web Milestone ksu-cis#2 changes
1 parent cc6c676 commit e0cc0ed

File tree

4 files changed

+143
-45
lines changed

4 files changed

+143
-45
lines changed

Data/Menu.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ namespace BleakwindBuffet.Data
1919
/// </summary>
2020
public static class Menu
2121
{
22+
/// <summary>
23+
/// Gets the possible order types
24+
/// </summary>
25+
public static string[] OrderTypes
26+
{
27+
get => new string[]
28+
{
29+
"Entree",
30+
"Side",
31+
"Drink"
32+
};
33+
}
34+
2235
/// <summary>
2336
/// Returns a list of entrees.
2437
/// </summary>
@@ -88,7 +101,7 @@ public static IEnumerable<IOrderItem> Drinks()
88101
var drinks = new List<IOrderItem>
89102
{
90103
// Without object initializer, the size defaults to small.
91-
// SailorSoda's flavor defaults to cherry if not within
104+
// Soda flavor defaults to cherry if not specified inside
92105
// the object initializer.
93106
new AretinoAppleJuice(),
94107
new AretinoAppleJuice() { Size = Size.Medium },
@@ -148,5 +161,29 @@ public static IEnumerable<IOrderItem> FullMenu()
148161

149162
return fullMenu;
150163
}
164+
165+
/// <summary>
166+
/// Searches the menu for matching items
167+
/// </summary>
168+
/// <param name="terms">The terms to search for</param>
169+
/// <returns>A collection of menu items</returns>
170+
public static IEnumerable<IOrderItem> Search(IEnumerable<IOrderItem> menu, string terms)
171+
{
172+
var results = new List<IOrderItem>();
173+
174+
// Return all menu items if search is blank
175+
if (terms == null) return menu;
176+
177+
// Check ToString method return value
178+
foreach (IOrderItem item in menu)
179+
{
180+
if (item.ToString().Contains(terms))
181+
{
182+
results.Add(item);
183+
}
184+
}
185+
186+
return results;
187+
}
151188
}
152189
}

Website/Pages/Index.cshtml

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,69 @@
88
<h1 class="display-4">Bleakwind Buffet</h1>
99
<p>We at Bleakwind Buffet are proud to bring you authentic fantasy meals straight from the world of Skyrim. Shake the blood off your sword and sake your thirst with one of our old-fashioned sailor sodas. Hack into a Smokehouse Skeleton with your dagger. Or vanquish the the mighty Thalmor Triple Burger! You’ve had a hard adventure and earned your loot, so spend it with us!</p>
1010
</div>
11+
1112
<hr />
12-
<p class="discount-notice">Combining any entree, side, and drink into a combo includes a $1 discount off the order.</p>
13+
14+
<p class="discount-notice">Combining any entree, side, and drink includes a $1 discount off the order.</p>
15+
1316
<hr />
14-
<h2 class="menu-items">Entrees</h2>
15-
@foreach (String item in Model.GetItems(IndexModel.OrderType.Entree))
16-
{
17-
<div class="menu-item">
18-
@item
19-
</div>
20-
}
21-
<br />
22-
<h2 class="menu-items">Sides</h2>
23-
@foreach (String item in Model.GetItems(IndexModel.OrderType.Side))
24-
{
25-
<div class="menu-item">
26-
@item
27-
</div>
28-
}
29-
<br />
30-
<h2 class="menu-items">Drinks</h2>
31-
@foreach (String item in Model.GetItems(IndexModel.OrderType.Drink))
32-
{
33-
<div class="menu-item">
34-
@item
17+
18+
<form id="menu">
19+
<div id="search-filters">
20+
<input type="text" name="SearchTerms" value="@Model.SearchTerms" />
21+
<input type="submit" value="Search">
22+
23+
<label>Calories</label>
24+
<input type="range" name="caloriesInput" id="calories" value="500" min="0" max="1000" step="10" oninput="caloriesDisplay.value = calories.value">
25+
<output name="caloriesOutput" id="caloriesDisplay">500</output> kcals
26+
27+
<label>Price</label>
28+
<input type="range" name="priceInput" id="price" value="5.00" min="0" max="10" step="0.1" oninput="priceDisplay.value = price.value">
29+
$<output name="priceOutput" id="priceDisplay">5.00</output>
3530
</div>
36-
}
37-
<hr />
38-
<h5>Sailor Soda Flavors</h5>
39-
<ul>
40-
@foreach (string flavor in Model.SailorSodaFlavors())
31+
<br />
32+
@if (!String.IsNullOrEmpty(Model.SearchTerms))
33+
{
34+
<h2 class="result-count">42 results</h2>
35+
// TODO: make stuff happen here
36+
}
37+
else
4138
{
42-
<li>
43-
@flavor
44-
</li>
39+
// Display full menu and Sailor Soda flavors
40+
<div id="results">
41+
<h2 class="menu-items">Entrees</h2>
42+
@foreach (String item in Model.GetItems(IndexModel.OrderType.Entree))
43+
{
44+
<div class="menu-item">
45+
@item
46+
</div>
47+
}
48+
<br />
49+
<h2 class="menu-items">Sides</h2>
50+
@foreach (String item in Model.GetItems(IndexModel.OrderType.Side))
51+
{
52+
<div class="menu-item">
53+
@item
54+
</div>
55+
}
56+
<br />
57+
<h2 class="menu-items">Drinks</h2>
58+
@foreach (String item in Model.GetItems(IndexModel.OrderType.Drink))
59+
{
60+
<div class="menu-item">
61+
@item
62+
</div>
63+
}
64+
</div>
65+
<hr />
66+
<h5>Sailor Soda Flavors</h5>
67+
<ul>
68+
@foreach (string flavor in Model.SailorSodaFlavors())
69+
{
70+
<li>
71+
@flavor
72+
</li>
73+
}
74+
</ul>
4575
}
46-
</ul>
76+
</form>

Website/Pages/Index.cshtml.cs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.AspNetCore.Mvc.RazorPages;
77
using Microsoft.Extensions.Logging;
8-
using BleakwindBuffet.Data.Entrees;
9-
using BleakwindBuffet.Data;
10-
using BleakwindBuffet.Data.Enums;
8+
using Data = BleakwindBuffet.Data;
119

1210
namespace Website.Pages
1311
{
12+
[BindProperties(SupportsGet = true)]
1413
public class IndexModel : PageModel
1514
{
1615
private readonly ILogger<IndexModel> _logger;
@@ -20,11 +19,26 @@ public IndexModel(ILogger<IndexModel> logger)
2019
_logger = logger;
2120
}
2221

23-
public void OnGet()
24-
{
22+
/// <summary>
23+
/// The items to display on the index page
24+
/// </summary>
25+
public IEnumerable<Data.IOrderItem> MenuItems { get; protected set; }
2526

26-
}
27+
/// <summary>
28+
/// The current search terms
29+
/// </summary>
30+
[BindProperty(SupportsGet = true)]
31+
public string SearchTerms { get; set; }
2732

33+
/// <summary>
34+
/// The filtered order types
35+
/// </summary>
36+
[BindProperty]
37+
public string[] Types { get; set; }
38+
39+
/// <summary>
40+
/// Order types from menu
41+
/// </summary>
2842
public enum OrderType
2943
{
3044
Entree,
@@ -33,37 +47,52 @@ public enum OrderType
3347
All
3448
}
3549

50+
public void OnGet()
51+
{
52+
MenuItems = Data.Menu.Search(Data.Menu.FullMenu(), SearchTerms);
53+
}
54+
55+
/// <summary>
56+
/// Returns a list of items by order type
57+
/// </summary>
58+
/// <param name="type">The order type</param>
59+
/// <returns>The string list of items</returns>
3660
public List<String> GetItems(OrderType type)
3761
{
38-
IEnumerable<IOrderItem> list = null;
62+
IEnumerable<Data.IOrderItem> list = null;
3963
var items = new List<String>();
4064

4165
switch(type)
4266
{
4367
case OrderType.Entree:
44-
list = Menu.Entrees();
68+
list = Data.Menu.Entrees();
4569
break;
4670
case OrderType.Side:
47-
list = Menu.Sides();
71+
list = Data.Menu.Sides();
4872
break;
4973
case OrderType.Drink:
50-
list = Menu.Drinks();
74+
list = Data.Menu.Drinks();
5175
break;
5276
case OrderType.All:
53-
list = Menu.FullMenu();
77+
list = Data.Menu.FullMenu();
5478
break;
5579
}
56-
foreach (IOrderItem item in list)
80+
81+
foreach(Data.IOrderItem item in list)
5782
{
5883
items.Add($"{item}, ${item.Price}, {item.Calories} kcals");
5984
}
6085
return items;
6186
}
6287

88+
/// <summary>
89+
/// Returns a list of available Sailor Soda flavors
90+
/// </summary>
91+
/// <returns>The string list of soda flavors</returns>
6392
public List<String> SailorSodaFlavors()
6493
{
6594
var list = new List<string>();
66-
foreach(SodaFlavor flavor in Enum.GetValues(typeof(SodaFlavor)))
95+
foreach(Data.Enums.SodaFlavor flavor in Enum.GetValues(typeof(Data.Enums.SodaFlavor)))
6796
{
6897
list.Add(flavor.ToString());
6998
}

Website/wwwroot/css/site.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ body {
7070
line-height: 60px; /* Vertically center the text there */
7171
}
7272

73+
/* Non-default additions
74+
-------------------------------------------------- */
7375
p.discount-notice {
7476
font-style: italic;
7577
}

0 commit comments

Comments
 (0)