Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }