Skip to content

Commit c2aeb4c

Browse files
AmyAmy
authored andcommitted
Web Milestone ksu-cis#2
1 parent 9846959 commit c2aeb4c

File tree

10 files changed

+268
-61
lines changed

10 files changed

+268
-61
lines changed

Data/Menu.cs

Lines changed: 169 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using System;
1212
using System.Collections.Generic;
1313
using System.Text;
14+
using System.Linq;
15+
1416

1517
namespace BleakwindBuffet.Data
1618
{
@@ -19,6 +21,21 @@ namespace BleakwindBuffet.Data
1921
/// </summary>
2022
public static class Menu
2123
{
24+
private static List<IOrderItem> items = new List<IOrderItem>();
25+
26+
/// <summary>
27+
/// Gets the item categories
28+
/// </summary>
29+
private static string[] ItemCategories
30+
{
31+
get => new string[]
32+
{
33+
"Entree",
34+
"Side",
35+
"Drink",
36+
};
37+
}
38+
2239
/// <summary>
2340
/// Collection of the entree items in an IEnumerable
2441
/// </summary>
@@ -37,7 +54,6 @@ public static IEnumerable<IOrderItem> Entrees()
3754
return items;
3855
}
3956

40-
4157
/// <summary>
4258
/// Collection of the side items in an IEnumerable
4359
/// </summary>
@@ -118,6 +134,157 @@ public static IEnumerable<IOrderItem> FullMenu()
118134

119135
return all;
120136
}
121-
137+
138+
/// <summary>
139+
/// searches for terms in a list of items
140+
/// </summary>
141+
/// <param name="terms">term to find</param>
142+
/// <returns>list of items containing the term</returns>
143+
public static IEnumerable<IOrderItem> Search(string terms)
144+
{
145+
List<IOrderItem> results = new List<IOrderItem>();
146+
147+
//null check
148+
if (terms == null) return FullMenu();
149+
150+
foreach (IOrderItem item in FullMenu())
151+
{
152+
//Add the item if there is a match
153+
if (item.Name != null && item.Name.Contains(terms))
154+
{
155+
results.Add(item);
156+
}
157+
158+
159+
}
160+
161+
return results;
162+
}
163+
164+
/// <summary>
165+
/// Filters the provided collection of items
166+
/// </summary>
167+
/// <param name="items">The collection of menu items to filter</param>
168+
/// <param name="categories">The categories to include</param>
169+
/// <returns>A collection containing only menu items that match the filter</returns>
170+
public static IEnumerable<IOrderItem> FilterByCategory(IEnumerable<IOrderItem> items, IEnumerable<string> categories)
171+
{
172+
// If no filter is specified, just return the provided collection
173+
if (categories == null || categories.Count() == 0) return items;
174+
175+
// Filter the supplied collection items based on the supplied categories
176+
List<IOrderItem> results = new List<IOrderItem>();
177+
foreach (string cat in categories)
178+
{
179+
if(cat=="Entree")
180+
{
181+
results.AddRange(Entrees());
182+
}
183+
if(cat=="Side")
184+
{
185+
results.AddRange(Sides());
186+
}
187+
if (cat == "Drink")
188+
{
189+
results.AddRange(Drinks());
190+
}
191+
}
192+
return results;
193+
}
194+
195+
/// <summary>
196+
/// Filters the provided collection
197+
/// to those with Calories falling within
198+
/// the specified range
199+
/// </summary>
200+
/// <param name="items">The collection of menu items to filter</param>
201+
/// <param name="min">The minimum range value</param>
202+
/// <param name="max">The maximum range value</param>
203+
/// <returns>The filtered movie collection</returns>
204+
public static IEnumerable<IOrderItem> FilterByCalories(IEnumerable<IOrderItem> items, uint? min, uint? max)
205+
{
206+
if ((min == null && max == null) || (min==0 && max ==0)) return FullMenu();
207+
208+
var results = new List<IOrderItem>();
209+
210+
// only a maximum specified
211+
if (min == null)
212+
{
213+
foreach (IOrderItem item in items)
214+
{
215+
if (item.Calories <= max) results.Add(item);
216+
}
217+
return results;
218+
}
219+
220+
// only a minimum specified
221+
if (max == null)
222+
{
223+
foreach (IOrderItem item in items)
224+
{
225+
if (item.Calories >= min) results.Add(item);
226+
}
227+
return results;
228+
}
229+
230+
// Both minimum and maximum specified
231+
foreach (IOrderItem item in items)
232+
{
233+
if (item.Calories >= min && item.Calories <= max)
234+
{
235+
results.Add(item);
236+
}
237+
}
238+
return results;
239+
240+
}
241+
242+
/// <summary>
243+
/// Filters the provided collection
244+
/// to those with a price falling within
245+
/// the specified range
246+
/// </summary>
247+
/// <param name="items">The collection of menu items to filter</param>
248+
/// <param name="min">The minimum range value</param>
249+
/// <param name="max">The maximum range value</param>
250+
/// <returns>The filtered collection</returns>
251+
public static IEnumerable<IOrderItem> FilterByPrice(IEnumerable<IOrderItem> items, double? min, double? max)
252+
{
253+
if (min == null && max == null || min== 0 && max ==0) return FullMenu();
254+
255+
var results = new List<IOrderItem>();
256+
257+
// only a maximum specified
258+
if (min == null || min == 0)
259+
{
260+
foreach (IOrderItem item in items)
261+
{
262+
if (item.Price <= max) results.Add(item);
263+
}
264+
return results;
265+
}
266+
267+
// only a minimum specified
268+
if (max == null || max == 0)
269+
{
270+
foreach (IOrderItem item in items)
271+
{
272+
if (item.Price >= min) results.Add(item);
273+
}
274+
return results;
275+
}
276+
277+
// Both minimum and maximum specified
278+
foreach (IOrderItem item in items)
279+
{
280+
if (item.Price >= min && item.Calories <= max)
281+
{
282+
results.Add(item);
283+
}
284+
}
285+
return results;
286+
287+
}
288+
122289
}
123290
}
1.92 KB
Binary file not shown.
1.6 KB
Binary file not shown.
1.52 KB
Binary file not shown.
224 Bytes
Binary file not shown.

Website/Pages/Index.cshtml

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,72 @@
55
}
66

77
<div class="text-center">
8-
<h1 class="display-4">Welcome to Bleakwind Buffet</h1>
9-
<p>
10-
We at Bleakwind Buffet are proud to bring you authentic fantasy meals straight from the world of Skyrim.
11-
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.
12-
Or vanquish the the mighty Thalmor Triple Burger! You’ve had a hard adventure and earned your loot, so spend it with us!.
13-
</p>
14-
<h2>Entrees</h2>
8+
<form id="menu">
9+
<div id="search">
10+
<input type="text" name="SearchTerms" value="@Model.SearchTerms" />
11+
<input type="submit" value="Search" />
12+
</div>
1513

16-
<ul class="menu-list">
17-
@foreach (BleakwindBuffet.Data.IOrderItem item in Model.Entrees)
18-
{
19-
<li>
20-
<div class="menu-item">
21-
<h3 class="name">@item.Name</h3>
22-
</div>
23-
<div class="details">
24-
<div class="price">@item.Price.ToString("C2")</div>
25-
<div class="calories">@item.Calories</div>
26-
</div>
27-
</li>
28-
}
29-
</ul>
14+
<div id="filters">
3015

31-
<h2>Sides</h2>
16+
<h4>Menu Categories</h4>
17+
@foreach (String cat in BleakwindBuffet.Data.Menu.ItemCategories)
18+
{
19+
<label>
20+
<input type="checkbox" name="ItemCategories" value="@cat" checked="@Model.ItemCategories" />
21+
@cat
22+
</label>
23+
}
3224

33-
<ul class="menu-list">
34-
@foreach (BleakwindBuffet.Data.IOrderItem item in Model.Sides)
35-
{
36-
<li>
37-
<div class="menu-item">
38-
<h3 class="name">@item.Name</h3>
25+
<h4>Calories</h4>
26+
<div>
27+
Between
28+
<input name="CalorieMin" type="number" min="0" max="1000" step="1" placeholder="min" />
29+
and
30+
<input name="CalorieMax" type="number" min="0" max="1000" step="1" placeholder="max" />
3931
</div>
40-
<div class="details">
41-
<div class="price">@item.Price</div>
42-
<div class="calories">@item.Calories</div>
32+
33+
<h4>Price</h4>
34+
<div>
35+
Between
36+
<input name="PriceMin" type="number" min="0" max="20" step="0.01" placeholder="min" />
37+
and
38+
<input name="PriceMax" type="number" min="0" max="20" step="0.01" placeholder="max" />
4339
</div>
44-
</li>
40+
41+
</div>
42+
<div id="main">
43+
<h1 class="display-4">Welcome to Bleakwind Buffet</h1>
44+
<p>
45+
We at Bleakwind Buffet are proud to bring you authentic fantasy meals straight from the world of Skyrim.
46+
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.
47+
Or vanquish the the mighty Thalmor Triple Burger! You’ve had a hard adventure and earned your loot, so spend it with us!.
48+
</p>
49+
50+
51+
<ul class="menu-list">
52+
@foreach (BleakwindBuffet.Data.IOrderItem item in Model.Items)
53+
{
54+
<li>
55+
<div class="menu-item">
56+
<h3 class="name">@item.Name</h3>
57+
</div>
58+
<div class="details">
59+
<div class="price">@item.Price.ToString("C2")</div>
60+
<div class="calories">@item.Calories</div>
61+
</div>
62+
</li>
63+
}
64+
</ul>
65+
4566

46-
}
47-
</ul>
4867

49-
<h2>Drinks</h2>
50-
<ul class="menu-list">
51-
@foreach (BleakwindBuffet.Data.IOrderItem item in Model.Drinks)
52-
{
53-
<li>
54-
<div class="menu-item">
55-
<h3 class="name">@item.Name</h3>
56-
</div>
57-
<div class="details">
58-
<div class="price">@item.Price</div>
59-
<div class="calories">@item.Calories</div>
60-
</div>
61-
</li>
62-
}
63-
</ul>
68+
<h2>Combos</h2>
69+
<p>Create a combo. Pick any entree, any side and any drink and receive a $1 discount.</p>
6470

65-
<h2>Combos</h2>
66-
<p>Create a combo. Pick any entree, any side and any drink and receive a $1 discount.</p>
71+
<h2>Soda Flavors</h2>
6772

68-
<h2>Soda Flavors</h2>
69-
70-
<p>Blackberry, Cherry, Grapefruit, Lemon, Peach, Watermelon</p>
71-
73+
<p>Blackberry, Cherry, Grapefruit, Lemon, Peach, Watermelon</p>
74+
</div>
75+
</form>
7276
</div>

Website/Pages/Index.cshtml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ namespace Website.Pages
1818
{
1919
public class IndexModel : PageModel
2020
{
21+
public IEnumerable<IOrderItem> Items { get; set; }
22+
23+
public string SearchTerms { get; set; }
24+
25+
public string[] ItemCategories { get; set; }
26+
2127
/// <summary>
2228
/// gets the list of entrees available
2329
/// </summary>
@@ -40,9 +46,13 @@ public IndexModel(ILogger<IndexModel> logger)
4046
_logger = logger;
4147
}
4248

43-
public void OnGet()
49+
public void OnGet(string SearchTerms, string[] ItemCategories, uint CalorieMin, uint CalorieMax,
50+
double PriceMin, double PriceMax)
4451
{
45-
52+
Items = Menu.Search(SearchTerms);
53+
Items = Menu.FilterByCategory(Items, ItemCategories);
54+
Items = Menu.FilterByCalories(Items, CalorieMin, CalorieMax);
55+
Items = Menu.FilterByPrice(Items, PriceMin, PriceMax);
4656
}
4757
}
4858
}

Website/Pages/Privacy.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ViewData["Title"] = "Privacy Policy";
55
}
66
<h1>@ViewData["Title"]</h1>
7-
<h1>Cowboy Cafe Website Privacy Policy</h1>
7+
<h1>Bleakwind Buffet Website Privacy Policy</h1>
88
<p>Bleakwind Buffet respects and values the privacy of its customers, as we hope you respect and value our own.
99
This site does not collect any data on you. This site does not use cookies.
1010
This site only displays information about Bleakwind Buffet and

Website/Pages/Shared/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>@ViewData["Title"] - Website - Cowboy Cafe</title>
6+
<title>@ViewData["Title"] - Website - Bleakwind Buffet</title>
77
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
88
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
99
</head>

0 commit comments

Comments
 (0)