Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;


namespace Boolean.CSharp.Main
{
public class Basket
{

private Dictionary<string, BasketItem> basket;
private int capacity;
private double totalPrice;
Inventory inventory;

public Basket()
{
this.basket = new Dictionary<string, BasketItem>();
this.capacity = 10;
this.totalPrice = 0;
this.inventory = new Inventory();
}

public int GetNumItemsInBasket()
{
int sum = 0;
foreach (KeyValuePair<string, BasketItem> item in basket)
{
sum += item.Value.Quantity;
}
return sum;
}

public double CalculateTotal()
{
double total = 0;
foreach (KeyValuePair<string, BasketItem> item in basket)
{
total += item.Value.Quantity * item.Value.GetPrice;
}
return total;
}

public string AddItem(string item, int quantity)
{
if ((GetNumItemsInBasket() + quantity) > capacity)
{
return "There is no room in your basket for this order";
}

if (!inventory.GetMapTypeVariantToSKU.ContainsKey("item"))
{
return "Im sorry, that is not on the menu";
}

// Add
string sku = inventory.GetMapTypeVariantToSKU[item];
if (basket.ContainsKey(sku))
{
basket[sku].Quantity += quantity;
}
else
{
basket.Add(sku, new BasketItem(
inventory.GetInventory[sku].GetName,
inventory.GetInventory[sku].GetType,
inventory.GetInventory[sku].GetPrice,
quantity));
}
// update price
TotalPrice = CalculateTotal();
return $"{basket[sku].GetNametype} has been added to the basket";
}

public string AddBagelWithFillings(int quantity, List<string> fillings)
{
if ((GetNumItemsInBasket() + quantity* (1 + fillings.Count)) > capacity) // each quantity is one bagle and num of fillings
{
return "There is no room in your basket for this order";
}

// Add plain bagle
if (basket.ContainsKey("BGLP"))
{
basket["BGLP"].Quantity += quantity;
}
else
{
basket.Add("BGLP", new BasketItem(
inventory.GetInventory["BGLP"].GetName,
inventory.GetInventory["BGLP"].GetType,
inventory.GetInventory["BGLP"].GetPrice,
quantity
));
}
// Add Fillings
foreach (string item in fillings)
{


if (!inventory.GetMapTypeVariantToSKU.ContainsKey(item))
{
continue;
}
string sku = inventory.GetMapTypeVariantToSKU[item];
if (basket.ContainsKey(sku))
{
basket[sku].Quantity += quantity;
}
else
{
basket.Add(sku, new BasketItem(
inventory.GetInventory[sku].GetName,
inventory.GetInventory[sku].GetType,
inventory.GetInventory[sku].GetPrice,
quantity));
}
}
// update price
TotalPrice = CalculateTotal();
return $"Plain Bagel and chosen Fillings has been added to the basket";
}

public string RemoveItem(string item)
{

string sku = inventory.GetMapTypeVariantToSKU[item];
if (!basket.ContainsKey(sku))
{
return "Item was not found in your basket";
}
// Remove
else
{
basket.Remove(sku);
}
// update price
TotalPrice = CalculateTotal();
return $"{inventory.GetInventory[sku].GetNametype} has been removed from the basket";
}



public int Capacity { get { return capacity; } set { capacity = value; } }
public double TotalPrice { get { return totalPrice; } set { totalPrice = value; } }
public double PriceOfItem(string item) { return inventory.GetInventory[inventory.GetMapTypeVariantToSKU[item]].GetPrice; }

public Dictionary<string, BasketItem> Baskets { get { return basket; } }
public BasketItem GetBasketitem(string sku) { return basket[sku]; }
public Inventory GetInventory { get { return inventory; } }

}
}
18 changes: 18 additions & 0 deletions exercise.main/BasketItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;


namespace Boolean.CSharp.Main
{
public class BasketItem : Item
{
public BasketItem(string name, string type, double price, int quantity)
: base(name, type, price, quantity) { }

public BasketItem(string name, string type, double price, int quantity, List<string> fillings)
: base(name, type, price, quantity, fillings) { }
}
}
49 changes: 49 additions & 0 deletions exercise.main/Inventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;


namespace Boolean.CSharp.Main
{
public class Inventory
{
private Dictionary<string, InventoryItem> inventory;
private Dictionary<String, String> mapTypeVariantToSKU;
private List<List<string>> itemsList = new List<List<string>>{
new List<string>{"BGLO", "0,49", "Bagel", "Onion"},
new List<string>{"BGLP", "0,39", "Bagel", "Plain"},
new List<string>{ "BGLE", "0,49", "Bagel", "Everything"},
new List<string>{ "BGLS", "0,49", "Bagel", "Sesame"},

new List<string>{ "COFB", "0,99", "Coffee", "Black"},
new List<string>{ "COFW", "1,19", "Coffee", "White"},
new List<string>{ "COFC", "1,29", "Coffee", "Capuccino"},
new List<string>{ "COFL", "1,29", "Coffee", "Latte"},

new List<string>{ "FILB", "0,12", "Filling", "Bacon"},
new List<string>{ "FILE", "0,12", "Filling", "Egg"},
new List<string>{ "FILC", "0,12", "Filling", "Cheese"},
new List<string>{ "FILX", "0,12", "Filling", "Cream Cheese"},
new List<string>{ "FILS", "0,12", "Filling", "Smoked Salmon"},
new List<string>{ "FILH", "0,12", "Filling", "Ham"}
};

public Inventory()
{
inventory = new Dictionary<string, InventoryItem>();
mapTypeVariantToSKU = new Dictionary<string, string>();

foreach (var item in itemsList)
{
inventory.Add(item[0], new InventoryItem(item[2], item[3], double.Parse(item[1]), 0));
mapTypeVariantToSKU.Add(inventory[item[0]].GetNametype, item[0]);
}
}

public Dictionary<string, InventoryItem> GetInventory { get { return inventory; } }
public Dictionary<String, String> GetMapTypeVariantToSKU { get { return mapTypeVariantToSKU; } }

}
}
15 changes: 15 additions & 0 deletions exercise.main/InventoryItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;


namespace Boolean.CSharp.Main
{
public class InventoryItem : Item
{
public InventoryItem(string name, string type, double price, int quantity)
: base(name, type, price, quantity) { }
}
}
57 changes: 57 additions & 0 deletions exercise.main/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;


namespace Boolean.CSharp.Main
{
public class Item
{
private string name;
private string type;
private string nametype;
private double price;
private int quantity;
private List<String> fillings;

public Item(string name, string type, double price, int quantity)
{
this.name = name;
this.type = type;
this.nametype = name + " " + type;
this.price = price;
this.quantity = quantity;
this.fillings = new List<String>();
}
public Item(string name, string type, double price, int quantity, List<string> fillings)
{
this.name = name;
this.type = type;
this.nametype = name + " " + type;
this.price = price;
this.quantity = quantity;
this.fillings = fillings;
}

public string GetName { get { return name; } }

public string GetType { get { return type; } }

public string GetNametype { get { return nametype; } }

public double GetPrice { get { return price; } }

public int Quantity { get { return quantity; } set { quantity = value; } }

public List<string> GetFillings { get { return fillings; } }







}
}
Loading