Skip to content

Commit

Permalink
Finished Point of Sale Milestone 3
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfschwartz committed Oct 11, 2020
1 parent 7bbee24 commit 955a671
Show file tree
Hide file tree
Showing 86 changed files with 2,860 additions and 1,546 deletions.
146 changes: 146 additions & 0 deletions Data/ComboMeal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Author: Matthew Schwartz
* Class name: ComboMeal.cs
* Purpose: Get and set properties for a combo meal object, which contains a drink, side, and entree item
*/

using BleakwindBuffet.Data.Drinks;
using BleakwindBuffet.Data.Entrees;
using BleakwindBuffet.Data.Sides;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace BleakwindBuffet.Data
{
public class ComboMeal : IOrderItem, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Name of this item, used in the order summary display list
/// </summary>
public string Name { get { return "Combo Meal"; } }

/// <summary>
/// Constructor for Combo meal. Attaches listeners for the current drink, side, and entree
/// </summary>
public ComboMeal()
{
drink.PropertyChanged += ComboPropertyChangedListener;
side.PropertyChanged += ComboPropertyChangedListener;
entree.PropertyChanged += ComboPropertyChangedListener;
}

/// <summary>
/// Drink property to represent which drink is in the combo meal
/// </summary>
private Drink drink = new SailorSoda();
public Drink Drink
{
get { return drink; }
set
{
drink.PropertyChanged -= ComboPropertyChangedListener;
drink = value;
drink.PropertyChanged += ComboPropertyChangedListener;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Drink"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Price"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Calories"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SpecialInstructions"));
}
}

/// <summary>
/// Side property to represent which drink is in the combo meal
/// </summary>
private Side side = new DragonbornWaffleFries();

public Side Side
{
get { return side; }
set
{
side.PropertyChanged -= ComboPropertyChangedListener;
side = value;
side.PropertyChanged += ComboPropertyChangedListener;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Side"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Price"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Calories"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SpecialInstructions"));
}
}

/// <summary>
/// Entree property to represent which drink is in the combo meal
/// </summary>
private Entree entree = new BriarheartBurger();
public Entree Entree
{
get { return entree; }
set
{
entree.PropertyChanged -= ComboPropertyChangedListener;
entree = value;
entree.PropertyChanged += ComboPropertyChangedListener;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Entree"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Price"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Calories"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SpecialInstructions"));
}
}

/// <summary>
/// Price property to represent how much the combo meal costs
/// </summary>
public double Price
{
get { return Math.Round(drink.Price + side.Price + entree.Price - 1.00, 2); }
}

/// <summary>
/// Calories property to represent how many calories are in the combo meal
/// </summary>
public uint Calories
{
get { return drink.Calories + side.Calories + entree.Calories; }
}

/// <summary>
/// Special instructions property to represent any special instructions for each item in the combo meal
/// </summary>
private List<string> specialInstructions;
public List<string> SpecialInstructions
{
get
{
specialInstructions = new List<string>();
specialInstructions.Add(entree.ToString());
specialInstructions.AddRange(entree.SpecialInstructions);
specialInstructions.Add(drink.ToString());
specialInstructions.AddRange(drink.SpecialInstructions);
specialInstructions.Add(side.ToString());
specialInstructions.AddRange(side.SpecialInstructions);
return specialInstructions;
}
}

void ComboPropertyChangedListener(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Price")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Price"));
}
if (e.PropertyName == "Calories")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Calories"));
}
if (e.PropertyName == "SpecialInstructions")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SpecialInstructions"));
}
}

}
}
22 changes: 13 additions & 9 deletions Data/Drinks/AretinoAppleJuice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace BleakwindBuffet.Data.Drinks
/// <summary>
/// Class defining a AretinoAppleJuice object
/// </summary>
public class AretinoAppleJuice : Drink, IOrderItem, INotifyPropertyChanged
public class AretinoAppleJuice : Drink, IOrderItem
{
public const double SMALL_ARETINO_APPLE_JUICE_PRICE = 0.62;
public const double MEDIUM_ARETINO_APPLE_JUICE_PRICE = 0.87;
Expand All @@ -24,7 +24,10 @@ public class AretinoAppleJuice : Drink, IOrderItem, INotifyPropertyChanged
public const uint MEDIUM_ARETINO_APPLE_JUICE_CALORIES = 88;
public const uint LARGE_ARETINO_APPLE_JUICE_CALORIES = 132;

public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Name of this item, used in the order summary display list
/// </summary>
public string Name { get { return this.ToString(); } }

private new Size size = Size.Small;
public override Size Size
Expand All @@ -33,11 +36,11 @@ public override Size Size
set
{
size = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Size"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Price"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Calories"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SpecialInstructions"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToString"));
OnPropertyChanged("Size");
OnPropertyChanged("Price");
OnPropertyChanged("Calories");
OnPropertyChanged("SpecialInstructions");
OnPropertyChanged("Name");
}
}

Expand Down Expand Up @@ -93,7 +96,7 @@ public bool Ice
set
{
ice = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Ice"));

if (ice)
{
specialInstructions.Add("Add ice");
Expand All @@ -102,7 +105,8 @@ public bool Ice
{
specialInstructions.Remove("Add ice");
}

OnPropertyChanged("Ice");
OnPropertyChanged("SpecialInstructions");
}
}

Expand Down
35 changes: 24 additions & 11 deletions Data/Drinks/CandlehearthCoffee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class CandlehearthCoffee : Drink, IOrderItem, INotifyPropertyChanged
public const uint MEDIUM_CANDLEHEARTH_COFFEE_CALORIES = 10;
public const uint LARGE_CANDLEHEARTH_COFFEE_CALORIES = 20;

public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Name of this item, used in the order summary display list
/// </summary>
public string Name { get { return this.ToString(); } }

private new Size size = Size.Small;
public override Size Size
Expand All @@ -33,11 +36,11 @@ public override Size Size
set
{
size = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Size"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Price"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Calories"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SpecialInstructions"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToString"));
OnPropertyChanged("Size");
OnPropertyChanged("Price");
OnPropertyChanged("Calories");
OnPropertyChanged("SpecialInstructions");
OnPropertyChanged("Name");
}
}

Expand Down Expand Up @@ -93,7 +96,7 @@ public bool Ice
set
{
ice = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Ice"));

if (ice)
{
specialInstructions.Add("Add ice");
Expand All @@ -102,7 +105,8 @@ public bool Ice
{
specialInstructions.Remove("Add ice");
}

OnPropertyChanged("Ice");
OnPropertyChanged("SpecialInstructions");
}
}

Expand All @@ -118,7 +122,7 @@ public bool RoomForCream
set
{
roomForCream = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("RoomForCream"));
OnPropertyChanged("RoomForCream");
if (roomForCream)
{
specialInstructions.Add("Add cream");
Expand All @@ -127,7 +131,7 @@ public bool RoomForCream
{
specialInstructions.Remove("Add cream");
}

OnPropertyChanged("SpecialInstructions");
}
}

Expand All @@ -143,7 +147,16 @@ public bool Decaf
set
{
decaf = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Decaf"));
OnPropertyChanged("Decaf");
if (decaf)
{
specialInstructions.Add("Decaf");
}
else
{
SpecialInstructions.Remove("Decaf");
}
OnPropertyChanged("SpecialInstructions");
}
}

Expand Down
13 changes: 12 additions & 1 deletion Data/Drinks/Drink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ namespace BleakwindBuffet.Data.Drinks
/// </summary>
public abstract class Drink
{
//public event PropertyChangedEventHandler PropertyChanged;
public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Property invokation method for this class and derived classes to use
/// </summary>
/// <param name="propertyName">Which property is being changed</param>
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}


/// <summary>
/// Size of a drink, all drinks have same size options (so virtual)
/// </summary>
Expand Down
19 changes: 11 additions & 8 deletions Data/Drinks/MarkarthMilk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class MarkarthMilk : Drink, IOrderItem, INotifyPropertyChanged
public const uint MEDIUM_MARKARTH_MILK_CALORIES = 72;
public const uint LARGE_MARKARTH_MILK_CALORIES = 93;

public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Name of this item, used in the order summary display list
/// </summary>
public string Name { get { return this.ToString(); } }

private new Size size = Size.Small;
public override Size Size
Expand All @@ -33,11 +36,11 @@ public override Size Size
set
{
size = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Size"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Price"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Calories"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SpecialInstructions"));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ToString"));
OnPropertyChanged("Size");
OnPropertyChanged("Price");
OnPropertyChanged("Calories");
OnPropertyChanged("SpecialInstructions");
OnPropertyChanged("Name");
}
}

Expand Down Expand Up @@ -93,7 +96,7 @@ public bool Ice
set
{
ice = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Ice"));
OnPropertyChanged("Ice");
if (ice)
{
specialInstructions.Add("Add ice");
Expand All @@ -102,7 +105,7 @@ public bool Ice
{
specialInstructions.Remove("Add ice");
}

OnPropertyChanged("SpecialInstructions");
}
}

Expand Down
Loading

0 comments on commit 955a671

Please sign in to comment.