Exemple #1
0
        public void FillInKit(Kit setOfFurniture, List <Table> tables, List <Chair> chairs)
        {
            TableServices tableServices      = new TableServices();
            ChairServices chairServices      = new ChairServices();
            int           generalCounter     = 0;
            int           smallWoodTable     = tableServices.CountTablesOfEachType("wood", "small", tables);
            int           smallPlasticTable  = tableServices.CountTablesOfEachType("plastic", "small", tables);
            int           smallGlassTable    = tableServices.CountTablesOfEachType("glass", "small", tables);
            int           woodPricedChair    = chairServices.GetChairsOfOneTypeAtOnePrice("wood", chairs, setOfChairs).Count();
            int           plasticPricedChair = chairServices.GetChairsOfOneTypeAtOnePrice("plastic", chairs, setOfChairs).Count();

            Console.WriteLine("Lets build a set of furniture from what we have in stock.");
            setOfFurniture.Name = FurnitureServices.GetNameOfSet();

            if (tables.Count() == 0)
            {
                Console.WriteLine("There is no tables in stock. Unfortunatelly we can not produce any set of furniture.");
            }
            else
            {
                while (generalCounter == 0)
                {
                    tableServices.FindTable(setOfFurniture, tables);
                    setOfChairs   = chairServices.GetNumberOfChairs(setOfFurniture);
                    chairMaterial = chairServices.GetChairMaterialType(setOfFurniture);
                    IEnumerable <Chair> chairsOfOneTypeAtOnePrice = chairServices.GetChairsOfOneTypeAtOnePrice(chairMaterial, chairs, setOfChairs);

                    if (chairsOfOneTypeAtOnePrice.Count() >= setOfChairs)
                    {
                        foreach (Chair y in chairsOfOneTypeAtOnePrice)
                        {
                            generalCounter++;
                            setOfFurniture.GetList().Add(y);
                            if (setOfFurniture.GetList().Count == setOfChairs)
                            {
                                int newCounter = 0;
                                foreach (var c in setOfFurniture.GetList())
                                {
                                    chairs.Remove(c);
                                }
                                foreach (Chair x in chairs)
                                {
                                    newCounter++;
                                }
                                tables.Remove(setOfFurniture.Table);
                                break;
                            }
                        }
                        Console.WriteLine($"\n{ShowResult(setOfFurniture)}");
                    }
                    else if ((chairsOfOneTypeAtOnePrice.Count() <= setOfChairs &&
                              (chairServices.GetChairsOfOneTypeAtOnePrice("wood", chairs, setOfChairs).Count() >= 2)) && (smallWoodTable > 0 || smallGlassTable > 0))
                    {
                        Console.WriteLine("Try other combinations.");
                    }
                    else if ((chairsOfOneTypeAtOnePrice.Count() <= setOfChairs &&
                              (chairServices.GetChairsOfOneTypeAtOnePrice("plastic", chairs, setOfChairs).Count() >= 2)) && (smallPlasticTable > 0 || smallGlassTable > 0))
                    {
                        Console.WriteLine("Try other combinations.");
                    }
                    else if (woodPricedChair < 2 || (woodPricedChair < 2 && (smallWoodTable < 1 || smallGlassTable < 1)) ||
                             plasticPricedChair < 2 || (plasticPricedChair < 2 && (smallPlasticTable < 1 || smallGlassTable < 1)))
                    {
                        generalCounter--;
                        Console.WriteLine("There is not enough chairs to make any set.");
                    }
                }
            }
        }