Example #1
0
        public ProductsBySupplierItem[] ProductsBySupplier()
        {
            using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create())
            {
                var productsBySupplier =
                    (from p in db.Products
                     group p by new { p.SupplierName }
                     into NewGroup
                     select new ProductsBySupplierItem()
                {
                    Count = NewGroup.Count(),
                    Supplier = NewGroup.Key.ToString()
                }
                    ).ToArray();

                return(productsBySupplier);
            }
        }
Example #2
0
        public static void ListResources(Farm farm, string id, string type)
        {
            IEnumerable <GrazingField> CorrectFieldEnumerable = from field in farm.GrazingFields
                                                                where field.ShortId == id
                                                                select field;

            List <GrazingField> CorrectFieldList = CorrectFieldEnumerable.ToList();

            GrazingField CorrectField = CorrectFieldList[0];

            IEnumerable <GrazingFieldReport> OrderedAnimals = (from animal in CorrectField.animalsList
                                                               group animal by animal.Type into NewGroup
                                                               select new GrazingFieldReport
            {
                AnimalType = NewGroup.Key,
                Number = NewGroup.Count().ToString()
            }
                                                               );


            List <GrazingFieldReport> AnimalList = OrderedAnimals.ToList();

            int count = 1;

            Console.WriteLine();
            Console.WriteLine("The following is in the Grazing Field:");
            Console.WriteLine();
            foreach (GrazingFieldReport animal in AnimalList)
            {
                Console.WriteLine($"{count}: {animal.Number} {animal.AnimalType}");
                count++;
            }

            Console.WriteLine();
            Console.WriteLine("Which resource should be processed?");
            Console.Write("> ");
            int choice          = Int32.Parse(Console.ReadLine());
            int correctedChoice = choice - 1;

            string AnimalType = AnimalList[correctedChoice].AnimalType;

            Console.WriteLine($"How many {AnimalType} should be processed? (Max 7)");
            int amountToProcess = Int32.Parse(Console.ReadLine());

            if (amountToProcess > 7)
            {
                Console.WriteLine("Learn to read, dumbass");
                amountToProcess = Int32.Parse(Console.ReadLine());
            }
            if (amountToProcess <= 7)
            {
                farm.ProcessingList.Add(new ToProcess
                {
                    FacilityId      = CorrectField.ShortId,
                    Type            = AnimalType,
                    AmountToProcess = amountToProcess
                });

                Console.WriteLine("Ready to process? (Y/n)");
                Console.Write("> ");
                string input = Console.ReadLine();

                switch (input)
                {
                case "Y":
                    break;

                case "n":
                    ChooseMeatProcessor.CollectInput(farm);
                    break;

                default:
                    break;
                }
            }
        }
Example #3
0
        public static void CollectInput(Farm farm, int number, string plantType)
        {
            Console.Clear();

            if (atCapacity)
            {
                atCapacity = false;
                Console.WriteLine($@"
**** That facililty is not large enough ****
****     Please choose another one      ****");

                for (int i = 0; i < farm.NaturalFields.Count; i++)
                {
                    Console.Write($"{i + 1}. Natural Field ");
                    IEnumerable <NaturalFieldReport> NaturalFlowers = (from flower in farm.NaturalFields[i].plantsList
                                                                       group flower by flower.Type into NewGroup
                                                                       select new NaturalFieldReport
                    {
                        PlantType = NewGroup.Key,
                        Number = NewGroup.Count().ToString()
                    }
                                                                       );
                    foreach (NaturalFieldReport flower in NaturalFlowers)
                    {
                        Console.Write($@"({flower.Number} {flower.PlantType})");
                    }

                    if (farm.NaturalFields[i].plantsList.Count < farm.NaturalFields[i].Capacity)
                    {
                        // Console.WriteLine($"{i + 1}. Natural Field ({farm.NaturalFields[i].plantsList.Count}/{farm.NaturalFields[i].Capacity})");
                    }
                    Console.WriteLine("\n");
                }

                Console.WriteLine();

                // How can I output the type of animal chosen here?
                Console.WriteLine($"Place the plant where?");

                Console.Write("> ");
                int choice          = Int32.Parse(Console.ReadLine());
                int correctedChoice = choice - 1;

                farm.NaturalFields[correctedChoice].AddResource(farm, number, plantType);
            }
            //runs the code if you don't need the at capacity message
            else
            {
                atCapacity = false;
                for (int i = 0; i < farm.NaturalFields.Count; i++)
                {
                    Console.Write($"{i + 1}. Natural Field ");
                    IEnumerable <NaturalFieldReport> NaturalFlowers = (from flower in farm.NaturalFields[i].plantsList
                                                                       group flower by flower.Type into NewGroup
                                                                       select new NaturalFieldReport
                    {
                        PlantType = NewGroup.Key,
                        Number = NewGroup.Count().ToString()
                    }
                                                                       );
                    foreach (NaturalFieldReport flower in NaturalFlowers)
                    {
                        Console.Write($@"({flower.Number} {flower.PlantType})");
                    }

                    if (farm.NaturalFields[i].plantsList.Count < farm.NaturalFields[i].Capacity)
                    {
                        // Console.WriteLine($"{i + 1}. Natural Field ({farm.NaturalFields[i].plantsList.Count}/{farm.NaturalFields[i].Capacity})");
                    }
                    Console.WriteLine("\n");
                }

                Console.WriteLine("\n");

                // How can I output the type of animal chosen here?
                Console.WriteLine($"Place the plant where?");

                Console.Write("> ");
                int choice = Int32.Parse(Console.ReadLine());
                //corrects the users choice to match the correct index
                int correctedChoice = choice - 1;

                farm.NaturalFields[correctedChoice].AddResource(farm, number, plantType);
            }

            /*
             *  Couldn't get this to work. Can you?
             *  Stretch goal. Only if the app is fully functional.
             */
            // farm.PurchaseResource<ICompostProducing>(animal, choice);
        }
        public static void ListResources(Farm farm, string id, string type)
        {
            IEnumerable <ChickenHouse> CorrectHouseEnumerable = from house in farm.ChickenHouses
                                                                where house.ShortId == id
                                                                select house;

            List <ChickenHouse> CorrectHouseList = CorrectHouseEnumerable.ToList();

            ChickenHouse CorrectHouse = CorrectHouseList[0];

            IEnumerable <ChickenHouseReport> OrderedChickens = (from chicken in CorrectHouse.animalsList
                                                                group chicken by chicken.Type into NewGroup
                                                                select new ChickenHouseReport
            {
                AnimalType = NewGroup.Key,
                Number = NewGroup.Count().ToString()
            }
                                                                );


            List <ChickenHouseReport> ChickenList = OrderedChickens.ToList();

            int count = 1;

            Console.WriteLine();
            Console.WriteLine("The following is in the Chicken House:");
            Console.WriteLine();
            foreach (ChickenHouseReport chicken in ChickenList)
            {
                Console.WriteLine($"{count}: {chicken.Number} {chicken.AnimalType}");
                count++;
            }

            Console.WriteLine();
            Console.WriteLine("Which resource should be processed?");
            Console.Write("> ");
            int choice          = Int32.Parse(Console.ReadLine());
            int correctedChoice = choice - 1;

            string AnimalType = ChickenList[correctedChoice].AnimalType;

            Console.WriteLine($"How many {AnimalType} should be processed? (Max 7)");
            int amountToProcess = Int32.Parse(Console.ReadLine());

            if (amountToProcess > 7)
            {
                Console.WriteLine("Learn to read, dumbass");
                amountToProcess = Int32.Parse(Console.ReadLine());
            }
            if (amountToProcess <= 5)
            {
                farm.ProcessingList.Add(new ToProcess
                {
                    FacilityId      = CorrectHouse.ShortId,
                    Type            = AnimalType,
                    AmountToProcess = amountToProcess
                });

                Console.WriteLine("Ready to process? (Y/n)");
                Console.Write("> ");
                string input = Console.ReadLine();

                switch (input)
                {
                case "Y":
                    break;

                case "n":
                    ChooseMeatProcessor.CollectInput(farm);
                    break;

                default:
                    break;
                }
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            // Find the words in the collection that start with the letter 'L'
            List <string> fruits = new List <string>()
            {
                "Lemon", "Apple", "Orange", "Lime", "Watermelon", "Loganberry"
            };

            IEnumerable <string> LFruits = from fruit in fruits
                                           where fruit.StartsWith("L")
                                           select fruit;

            foreach (string fruit in LFruits)
            {
                // Console.WriteLine($"{fruit}");
            }

            // Which of the following numbers are multiples of 4 or 6
            List <int> numbers = new List <int>()
            {
                15, 8, 21, 24, 32, 13, 30, 12, 7, 54, 48, 4, 49, 96
            };

            IEnumerable <int> fourSixMultiples = numbers.Where(num => num % 4 == 0 || num % 6 == 0);

            foreach (int num in fourSixMultiples)
            {
                // Console.WriteLine($"{num}");
            }

            // Order these student names alphabetically, in descending order (Z to A)
            // List<string> names = new List<string>()
            // {
            //     "Heather", "James", "Xavier", "Michelle", "Brian", "Nina",
            //     "Kathleen", "Sophia", "Amir", "Douglas", "Zarley", "Beatrice",
            //     "Theodora", "William", "Svetlana", "Charisse", "Yolanda",
            //     "Gregorio", "Jean-Paul", "Evangelina", "Viktor", "Jacqueline",
            //     "Francisco", "Tre"
            // };

            // List<string> descend = (from name in names
            // orderby name descending
            // select name).ToList();

            // foreach (string name in descend)
            // {
            //     Console.WriteLine($"{name}");
            // }

            // Code below also solves the issue.
            List <string> names = new List <string>()
            {
                "Heather", "James", "Xavier", "Michelle", "Brian", "Nina",
                "Kathleen", "Sophia", "Amir", "Douglas", "Zarley", "Beatrice",
                "Theodora", "William", "Svetlana", "Charisse", "Yolanda",
                "Gregorio", "Jean-Paul", "Evangelina", "Viktor", "Jacqueline",
                "Francisco", "Tre"
            };

            IEnumerable <string> descend = from name in names
                                           orderby name descending
                                           select name;

            foreach (string name in descend)
            {
                // Console.WriteLine($"{name}");
            }

            // Build a collection of these numbers sorted in ascending order
            List <int> numbersList = new List <int>()
            {
                15, 8, 21, 24, 32, 13, 30, 12, 7, 54, 48, 4, 49, 96
            };

            IEnumerable <int> ascendingNum = from numb in numbersList
                                             orderby numb ascending
                                             select numb;

            foreach (int numb in ascendingNum)
            {
                // Console.WriteLine($"{numb}");
            }

            // Output how many numbers are in this list
            List <int> numbersList3 = new List <int>()
            {
                15, 8, 21, 24, 32, 13, 30, 12, 7, 54, 48, 4, 49, 96
            };
            // Console.WriteLine($"There are {numbersList3.Count()} numbers in the list");

            // How much money have we made?
            List <double> purchases = new List <double>()
            {
                2340.29, 745.31, 21.76, 34.03, 4786.45, 879.45, 9442.85, 2454.63, 45.65
            };
            // Console.WriteLine($"We have made ${purchases.Sum()}.");

            // What is our most expensive product?
            List <double> prices = new List <double>()
            {
                879.45, 9442.85, 2454.63, 45.65, 2340.29, 34.03, 4786.45, 745.31, 21.76
            };

            // Console.WriteLine($"Our most expensive product is ${prices.Max()}");

            /*
             *  Store each number in the following List until a perfect square
             *  is detected.
             *
             *  Ref: https://msdn.microsoft.com/en-us/library/system.math.sqrt(v=vs.110).aspx
             */
            List <int> wheresSquaredo = new List <int>()
            {
                66, 12, 8, 27, 82, 34, 7, 50, 19, 46, 81, 23, 30, 4, 68, 14
            };

            foreach (int sqn in wheresSquaredo)
            {
                if (Math.Sqrt(sqn) % 1 == 0)
                {
                    // Console.WriteLine($"Square numbers in the list are: {sqn}");
                }
            }

            // Create some banks and store in a List
            List <Bank> banks = new List <Bank>()
            {
                new Bank()
                {
                    Name = "First Tennessee", Symbol = "FTB"
                },
                new Bank()
                {
                    Name = "Wells Fargo", Symbol = "WF"
                },
                new Bank()
                {
                    Name = "Bank of America", Symbol = "BOA"
                },
                new Bank()
                {
                    Name = "Citibank", Symbol = "CITI"
                },
            };

            List <Customer> customers = new List <Customer>()
            {
                new Customer()
                {
                    Name = "Bob Lesman", Balance = 80345.66, Bank = "FTB"
                },
                new Customer()
                {
                    Name = "Joe Landy", Balance = 9284756.21, Bank = "WF"
                },
                new Customer()
                {
                    Name = "Meg Ford", Balance = 487233.01, Bank = "BOA"
                },
                new Customer()
                {
                    Name = "Peg Vale", Balance = 7001449.92, Bank = "BOA"
                },
                new Customer()
                {
                    Name = "Mike Johnson", Balance = 790872.12, Bank = "WF"
                },
                new Customer()
                {
                    Name = "Les Paul", Balance = 8374892.54, Bank = "WF"
                },
                new Customer()
                {
                    Name = "Sid Crosby", Balance = 957436.39, Bank = "FTB"
                },
                new Customer()
                {
                    Name = "Sarah Ng", Balance = 56562389.85, Bank = "FTB"
                },
                new Customer()
                {
                    Name = "Tina Fey", Balance = 1000000.00, Bank = "CITI"
                },
                new Customer()
                {
                    Name = "Sid Brown", Balance = 49582.68, Bank = "CITI"
                }
            };

            // Build a collection of customers who are millionaires
            IEnumerable <Customer> millionaires = customers.Where(mill => mill.Balance >= 1000000);

            foreach (Customer mill in millionaires)
            {
                // Console.WriteLine($"{mill.Name}'s balance is ${mill.Balance}. They bank with {mill.Bank}.");
            }

            IEnumerable <BankReport> BankMills = (from bank in customers
                                                  group bank by bank.Bank into NewGroup
                                                  // created new class to store names of millionaires and which banks they are at
                                                  select new BankReport
            {
                Name = NewGroup.Key,
                BankMilionaires = NewGroup.Count()
            }).OrderByDescending(bm => bm.BankMilionaires).ToList();

            foreach (BankReport bank in BankMills)
            {
                // Console.WriteLine($"{bank.Name} {bank.BankMilionaires}");
            }

            var results = millionaires.GroupBy(
                p => p.Bank,
                (key, g) => new { Bank = key, p = g.Count() });

            foreach (var item in results)
            {
                Console.WriteLine($"{item.Bank} {item.p}");
            }

            // Create some banks and store in a List
            List <Bank> banks1 = new List <Bank>()
            {
                new Bank()
                {
                    Name = "First Tennessee", Symbol = "FTB"
                },
                new Bank()
                {
                    Name = "Wells Fargo", Symbol = "WF"
                },
                new Bank()
                {
                    Name = "Bank of America", Symbol = "BOA"
                },
                new Bank()
                {
                    Name = "Citibank", Symbol = "CITI"
                },
            };

            // Create some customers and store in a List
            List <Customer> newCustomers = new List <Customer>()
            {
                new Customer()
                {
                    Name = "Bob Lesman", Balance = 80345.66, Bank = "FTB"
                },
                new Customer()
                {
                    Name = "Joe Landy", Balance = 9284756.21, Bank = "WF"
                },
                new Customer()
                {
                    Name = "Meg Ford", Balance = 487233.01, Bank = "BOA"
                },
                new Customer()
                {
                    Name = "Peg Vale", Balance = 7001449.92, Bank = "BOA"
                },
                new Customer()
                {
                    Name = "Mike Johnson", Balance = 790872.12, Bank = "WF"
                },
                new Customer()
                {
                    Name = "Les Paul", Balance = 8374892.54, Bank = "WF"
                },
                new Customer()
                {
                    Name = "Sid Crosby", Balance = 957436.39, Bank = "FTB"
                },
                new Customer()
                {
                    Name = "Sarah Ng", Balance = 56562389.85, Bank = "FTB"
                },
                new Customer()
                {
                    Name = "Tina Fey", Balance = 1000000.00, Bank = "CITI"
                },
                new Customer()
                {
                    Name = "Sid Brown", Balance = 49582.68, Bank = "CITI"
                }
            };

            /*
             *  You will need to use the `Where()`
             *  and `Select()` methods to generate
             *  instances of the following class.
             *
             */

            List <ReportItem> millionaireReport = newCustomers
                                                  .Where(cust => cust.Balance >= 1000000)
                                                  .OrderBy(cust => cust.Name.Split(" ")[1])
                                                  .Select(cust => new ReportItem
            {
                CustomerName = cust.Name,
                BankName     = banks1.First(bank => bank.Symbol == cust.Bank).Name
                               // BankName = banks1.FirstOrDefault(x => x.Symbol == cust.Bank);
            }).ToList();

            foreach (ReportItem item in millionaireReport)
            {
                Console.WriteLine($"{item.CustomerName} at {item.BankName}");
            }
        }
        public static void ListResources(Farm farm, string id, string type, int alreadyProcessedSunflowers)
        {
            IEnumerable<NaturalField> CorrectFieldEnumerable = from field in farm.NaturalFields
                                                               where field.ShortId == id
                                                               select field;

            List<NaturalField> CorrectFieldList = CorrectFieldEnumerable.ToList();

            NaturalField CorrectField = CorrectFieldList[0];

            IEnumerable<NaturalFieldReport> OrderedFlowers = (from flower in CorrectField.plantsList
                                                              group flower by flower.Type into NewGroup
                                                              select new NaturalFieldReport
                                                              {
                                                                  PlantType = NewGroup.Key,
                                                                  Number = NewGroup.Count().ToString()
                                                              }
                );

            IEnumerable<NaturalFieldReport> JustSunflowers = from flower in OrderedFlowers
                                                             where flower.PlantType == "Sunflower"
                                                             select flower;

            List<NaturalFieldReport> OrderedSunflowersList = JustSunflowers.ToList();

            int count = 1;

            int numberToCheckSunflower = 0;

            Console.WriteLine();
            Console.WriteLine("The following flowers can be processed in the Natural Field");
            Console.WriteLine();
            foreach (NaturalFieldReport flower in JustSunflowers)
            {
                numberToCheckSunflower = Int32.Parse(flower.Number) - alreadyProcessedSunflowers;
                Console.WriteLine($"{count}: {numberToCheckSunflower} {flower.PlantType}");
                count++;
            }

            Console.WriteLine();
            Console.WriteLine("Which resource should be processed?");
            Console.Write("> ");
            int choice = Int32.Parse(Console.ReadLine());
            int correctedChoice = choice - 1;

            string PlantType = OrderedSunflowersList[correctedChoice].PlantType;

            Console.WriteLine($"How many {PlantType} should be processed? (Max 5)");
            int amountToProcess = Int32.Parse(Console.ReadLine());

            while (amountToProcess > 5)
            {
                Console.WriteLine("Yo I can't process that much at once, dumbass");
                amountToProcess = Int32.Parse(Console.ReadLine());
            }
            while (amountToProcess > numberToCheckSunflower)
            {
                Console.WriteLine("Yo there aren't that many to process, dumbass");
                amountToProcess = Int32.Parse(Console.ReadLine());
            }

            farm.ProcessingList.Add(new ToProcess
            {
                FacilityId = CorrectField.ShortId,
                Type = PlantType,
                AmountToProcess = amountToProcess
            });

            Console.WriteLine("Ready to process? (Y/n)");
            Console.Write("> ");
            string input = Console.ReadLine();

            switch (input)
            {
                case "Y":
                    break;
                case "n":
                    ChooseSeedHarvester.CollectInput(farm);
                    break;
                default:
                    break;
            }
        }