Skip to content

Commit

Permalink
Finished Website Milestone 2
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfschwartz committed Nov 6, 2020
1 parent 2f4cb30 commit ba2a564
Show file tree
Hide file tree
Showing 10 changed files with 591 additions and 142 deletions.
2 changes: 2 additions & 0 deletions Data/Entrees/Entree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public abstract class Entree
{
public event PropertyChangedEventHandler PropertyChanged;

public string ItemCategory = "Entree";

/// <summary>
/// Property invokation method for this class and derived classes to use
/// </summary>
Expand Down
127 changes: 127 additions & 0 deletions Data/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,133 @@ namespace BleakwindBuffet.Data
/// </summary>
public static class Menu
{
/// <summary>
/// Property that represents each category of menu item
/// </summary>
public static string[] ItemCategory { get; } = { "Entree", "Drink", "Side" };

/// <summary>
/// Performs a search
/// </summary>
/// <param name="term">The searching term</param>
/// <returns>A collection of IOrderItems that contain the searching term</returns>
public static IEnumerable<IOrderItem> Search(string term)
{
if (term == null)
{
return FullMenu();
}

List<IOrderItem> results = new List<IOrderItem>();
foreach(IOrderItem item in FullMenu())
{
if (item.ToString().ToLower().Contains(term.ToLower()))
{
results.Add(item);
}
}
return results;
}

/// <summary>
/// Filters a search based on item category
/// </summary>
/// <param name="orderItems">Collection of items we are filtering on</param>
/// <param name="categories">Collection of item categories we are filtering down to</param>
/// <returns>A new collection of items that only includes items of type category</returns>
public static IEnumerable<IOrderItem> FilterByCategory(IEnumerable<IOrderItem> orderItems, IEnumerable<string> categories)
{
if (categories == null || categories.Count() == 0) return orderItems;

List<IOrderItem> results = new List<IOrderItem>();
foreach(IOrderItem item in orderItems)
{
if (item is Entree entree)
{
if (categories.Contains("Entree")) results.Add(item);
}
else if (item is Drink drink)
{
if (categories.Contains("Drink")) results.Add(item);
}
else if (item is Side side)
{
if (categories.Contains("Side")) results.Add(item);
}
}
return results;
}

/// <summary>
/// Filters order items based on calories
/// </summary>
/// <param name="orderItems">Collection of items we are filtering on</param>
/// <param name="min">Minimum calorie count</param>
/// <param name="max">Maximum calorie count</param>
/// <returns>A new collection of items that all have a calorie count that falls between the min and max</returns>
public static IEnumerable<IOrderItem> FilterByCalories(IEnumerable<IOrderItem> orderItems, uint? min, uint? max)
{
if (min == null && max == null) return orderItems;

List<IOrderItem> results = new List<IOrderItem>();
if (min == null)
{
foreach(IOrderItem item in orderItems)
{
if (item.Calories <= max) results.Add(item);
}
}

if (max == null)
{
foreach (IOrderItem item in orderItems)
{
if (item.Calories >= min) results.Add(item);
}
}

foreach (IOrderItem item in orderItems)
{
if (item.Calories >= min && item.Calories <= max) results.Add(item);
}
return results;
}

/// <summary>
/// Filters items based on price
/// </summary>
/// <param name="orderItems">Collection of items we are filering on</param>
/// <param name="min">Minimum price</param>
/// <param name="max">Maximum price</param>
/// <returns>A new collection of items that all have a price that falls between the min and max</returns>
public static IEnumerable<IOrderItem> FilterByPrice(IEnumerable<IOrderItem> orderItems, double? min, double? max)
{
if (min == null && max == null) return orderItems;

List<IOrderItem> results = new List<IOrderItem>();
if (min == null)
{
foreach (IOrderItem item in orderItems)
{
if (item.Price <= max) results.Add(item);
}
}

if (max == null)
{
foreach (IOrderItem item in orderItems)
{
if (item.Price >= min) results.Add(item);
}
}

foreach (IOrderItem item in orderItems)
{
if (item.Price >= min && item.Price <= max) results.Add(item);
}
return results;
}

/// <summary>
/// Creates a list of all the possible entrees.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions DataTests/DataTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ItemGroup>
<ProjectReference Include="..\Data\Data.csproj" />
<ProjectReference Include="..\PointOfSale\PointOfSale.csproj" />
<ProjectReference Include="..\Website\Website.csproj" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions DataTests/ILoggerMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace BleakwindBuffet.DataTests
{
public class ILoggerMock<T> : ILogger<T>
{
public IDisposable BeginScope<TState>(TState state)
{
throw new NotImplementedException();
}

public bool IsEnabled(LogLevel logLevel)
{
throw new NotImplementedException();
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit ba2a564

Please sign in to comment.