public Customer(string fName, string lName, ChocolateOrder order) { FirstName = fName; LastName = lName; ChocoOrders = new List <ChocolateOrder>(); ChocoOrders.Add(order); }
/// <summary> /// Takes as parameteres the Store that is placing the order and the information about the chocolates to "extraxt" from the warehouse /// Returns a chocolate order containing a list of chocolates representing actual objects from the warehouse fot he factory /// </summary> /// <returns></returns> public ChocolateOrder ShipChocolateOrder(Store storeRelated, ChocolateOrder order) { //variables to keep track of number of items to remove from warehouse int darkChocos = 0; int whiteChocos = 0; int milkChocos = 0; int peanutChocos = 0; int almondChocos = 0; //Modifying valye of variables depending on data foreach (var chocolate in order.Chocolates) { if (chocolate.ChocolateKind == Kind.White) { whiteChocos += 1; } else if (chocolate.ChocolateKind == Kind.Peanut) { peanutChocos += 1; } else if (chocolate.ChocolateKind == Kind.Milk) { milkChocos += 1; } else if (chocolate.ChocolateKind == Kind.Dark) { darkChocos += 1; } else //(ChocolateKind == Kind.Almond) { almondChocos += 1; } } List <Chocolate> chocolatesList = new List <Chocolate>();//Creating the list that we will use to create the returning chocolate order //Before starting to take chocolates from chocolate Stock, we check if any of them is expired DeleteExpiredChocolatesInFactory(); //Querying the values from warehouse to create lists List <Chocolate> darkCholatesFromWarehouse = ChocolateExtractionFromStock(darkChocos, Kind.Dark); List <Chocolate> whiteCholatesFromWarehouse = ChocolateExtractionFromStock(whiteChocos, Kind.White); List <Chocolate> milkCholatesFromWarehouse = ChocolateExtractionFromStock(milkChocos, Kind.Milk); List <Chocolate> peanutCholatesFromWarehouse = ChocolateExtractionFromStock(peanutChocos, Kind.Peanut); List <Chocolate> almondCholatesFromWarehouse = ChocolateExtractionFromStock(almondChocos, Kind.Almond); chocolatesList = AddRemoveChocolates(darkCholatesFromWarehouse, chocolatesList); chocolatesList = AddRemoveChocolates(whiteCholatesFromWarehouse, chocolatesList); chocolatesList = AddRemoveChocolates(milkCholatesFromWarehouse, chocolatesList); chocolatesList = AddRemoveChocolates(peanutCholatesFromWarehouse, chocolatesList); chocolatesList = AddRemoveChocolates(almondCholatesFromWarehouse, chocolatesList); ChocolateOrder newOrder = new ChocolateOrder(chocolatesList, this, storeRelated); OrdersConducted.Add(newOrder); return(newOrder); }
public void ResupplyChocolate(Factory factoryRelated) { List <Chocolate> chocolatesListRequest = Chocolate.CreateChocolatesRequest(); ChocolateOrder newChocolatesRequest = new ChocolateOrder(chocolatesListRequest, factoryRelated, this); //Chocolates list is used to produce an order tracking the relation between store and customer and assigning price data ChocolateOrder chocolatesDelivery = factoryRelated.ShipChocolateOrder(this, newChocolatesRequest); //Invoking factory method passing the current store to return a valid representation of chocolate data, extracted from the factory's chocolate stock foreach (var item in chocolatesDelivery.Chocolates) //Populating store chocolate stock catalog { Chocolates.Add(item); } Console.WriteLine("Resupply was successful"); }
public void SellChocolateOrder(List <Chocolate> chocolatesSelected, Customer customer) { //list imported should be used to pass amount value of each kind to variables //Then create 5 lists querying items from the store's chcolate stock depending on date (to get rid of old ones first) //Loop every list you produced and populate a new list with each item, while also removing it from the stock //Use the produced list to create an order which you store on the Transactions list of the store, to keep track of the income aswell int darkChocos = 0; int whiteChocos = 0; int milkChocos = 0; int peanutChocos = 0; int almondChocos = 0; foreach (var chocolate in chocolatesSelected) { if (chocolate.ChocolateKind == Kind.White) { whiteChocos += 1; } else if (chocolate.ChocolateKind == Kind.Peanut) { peanutChocos += 1; } else if (chocolate.ChocolateKind == Kind.Milk) { milkChocos += 1; } else if (chocolate.ChocolateKind == Kind.Dark) { darkChocos += 1; } else //(ChocolateKind == Kind.Almond) { almondChocos += 1; } } //Before starting to take chocolates from the list of chocolates, we check if any of them is expired DeleteExpiredChocolatesInStore(); var almondChocolates = (from c in Chocolates where c.ChocolateKind == Kind.Almond orderby c.DateProduced ascending select c).Take(almondChocos); var whiteChocolates = (from c in Chocolates where c.ChocolateKind == Kind.White orderby c.DateProduced ascending select c).Take(whiteChocos); var darkChocolates = (from c in Chocolates where c.ChocolateKind == Kind.Dark orderby c.DateProduced ascending select c).Take(darkChocos); var peanutChocolates = (from c in Chocolates where c.ChocolateKind == Kind.Peanut orderby c.DateProduced ascending select c).Take(peanutChocos); var milkChocolates = (from c in Chocolates where c.ChocolateKind == Kind.Milk orderby c.DateProduced ascending select c).Take(milkChocos); List <Chocolate> chocolatesList = new List <Chocolate>(); foreach (var item in almondChocolates) { chocolatesList.Add(item); //Adding selected values to our list Chocolates.Remove(item); //Removing them from warehouse } foreach (var item in whiteChocolates) { chocolatesList.Add(item); Chocolates.Remove(item); } foreach (var item in darkChocolates) { chocolatesList.Add(item); Chocolates.Remove(item); } foreach (var item in peanutChocolates) { chocolatesList.Add(item); Chocolates.Remove(item); } foreach (var item in milkChocolates) { chocolatesList.Add(item); Chocolates.Remove(item); } ChocolateOrder newOrder = new ChocolateOrder(chocolatesList, this, customer); customer.ChocoOrders.Add(newOrder); this.Transactions.Add(newOrder); bool customerExists = false; foreach (var existingCustomer in Customers) { if (existingCustomer.Equals(customer)) { customerExists = true; } } if (!customerExists) { Customers.Add(customer); } Income += newOrder.TotalPrice; }
/// <summary> /// Takes as parameteres the Store that is placing the order and the information about the chocolates to "extraxt" from the warehouse /// Returns a chocolate order containing a list of chocolates representing actual objects from the warehouse fot he factory /// </summary> /// <returns></returns> public ChocolateOrder ShipChocolateOrder(Store storeRelated, ChocolateOrder order) { //variables to keep track of number of items to remove from warehouse int darkChocos = 0; int whiteChocos = 0; int milkChocos = 0; int peanutChocos = 0; int almondChocos = 0; //Modifying valye of variables depending on data foreach (var chocolate in order.Chocolates) { if (chocolate.ChocolateKind == Kind.White) { whiteChocos += 1; } else if (chocolate.ChocolateKind == Kind.Peanut) { peanutChocos += 1; } else if (chocolate.ChocolateKind == Kind.Milk) { milkChocos += 1; } else if (chocolate.ChocolateKind == Kind.Dark) { darkChocos += 1; } else //(ChocolateKind == Kind.Almond) { almondChocos += 1; } } List <Chocolate> chocolatesList = new List <Chocolate>();//Creating the list that we will use to create the returning chocolate order //Querying the values from warehouse to create lists var almondChocolates = ChocolateListQuery(almondChocos, "Almond"); var whiteChocolates = ChocolateListQuery(whiteChocos, "White"); var darkChocolates = ChocolateListQuery(darkChocos, "Dark"); var peanutChocolates = ChocolateListQuery(peanutChocos, "Peanut"); var milkChocolates = ChocolateListQuery(milkChocos, "Milk"); //var whiteChocolates = (from c in ChocolateWarehouse // where c.ChocolateKind == Kind.White // orderby c.DateProduced ascending // select c).Take(whiteChocos); //var darkChocolates = (from c in ChocolateWarehouse // where c.ChocolateKind == Kind.Dark // orderby c.DateProduced ascending // select c).Take(darkChocos); //var peanutChocolates = (from c in ChocolateWarehouse // where c.ChocolateKind == Kind.Peanut // orderby c.DateProduced ascending // select c).Take(peanutChocos); //var milkChocolates = (from c in ChocolateWarehouse // where c.ChocolateKind == Kind.Milk // orderby c.DateProduced ascending // select c).Take(milkChocos); //foreach (var item in almondChocolates) //{ // chocolatesList.Add(item); //Adding selected values to our list // ChocolateWarehouse.Remove(item);//Removing them from warehouse //} //foreach (var item in whiteChocolates) //{ // chocolatesList.Add(item); // ChocolateWarehouse.Remove(item); //} //foreach (var item in darkChocolates) //{ // chocolatesList.Add(item); // ChocolateWarehouse.Remove(item); //} //foreach (var item in peanutChocolates) //{ // chocolatesList.Add(item); // ChocolateWarehouse.Remove(item); //} AddRemoveChocolates(chocolatesList, milkChocolates); AddRemoveChocolates(chocolatesList, peanutChocolates); AddRemoveChocolates(chocolatesList, darkChocolates); AddRemoveChocolates(chocolatesList, whiteChocolates); AddRemoveChocolates(chocolatesList, almondChocolates); ChocolateOrder newOrder = new ChocolateOrder(chocolatesList, this, storeRelated); OrdersConducted.Add(newOrder); return(newOrder); }