Beispiel #1
0
        public void Exercise4()
        {
            // Declare repositories
            MinionRepository  minionRepository  = new MinionRepository();
            TownRepository    townRepository    = new TownRepository();
            VillainRepository villainRepository = new VillainRepository();

            //Promote the towns
            foreach (var item in townRepository.GetAll())
            {
                Console.WriteLine($"Id : {item.Id}\t Name: {item.Name}");
            }

            //Get the Minion data
            Console.WriteLine("Enter Minion Info:Name-Age-TownName");
            string line        = Console.ReadLine();
            var    minionLines = line.Split('-');
            Town   town        = townRepository.GetByName(minionLines[2]);

            //if town does not exist condition
            if (town == null)
            {
                town           = new Town();
                town.Name      = minionLines[2];
                town.CountryId = 1;
                townRepository.Insert(town);
                town = townRepository.GetByName(town.Name);
                Console.WriteLine($"Town {town.Name} was added to the database.");
            }
            //Read info of its villain
            Console.WriteLine("Enter Villain Name");
            string  villainName = Console.ReadLine();
            Villain villain     = villainRepository.GetByName(villainName);

            //if town does not exist condition
            if (villain == null)
            {
                villain                  = new Villain();
                villain.Name             = villainName;
                villain.EvilnessFactorId = 3;
                villainRepository.Insert(villain);
                villain = villainRepository.GetByName(villain.Name);
                Console.WriteLine($"Villain  {villain.Name} was added to the database.");
            }
            Minion minion = new Minion();

            minion.Name   = minionLines[0];
            minion.Age    = Convert.ToInt32(minionLines[1]);
            minion.TownId = town.Id;
            minionRepository.Insert(minion);
            minion = minionRepository.GetByName(minion.Name);
            if (RelationshipsRepository.AddNewMinionToVillain(minion, villain) > 0)
            {
                Console.WriteLine($"Successfully added {minion.Name} to be minion of {villain.Name}.");
            }

            Console.ReadKey();
        }
Beispiel #2
0
 private static IEnumerable <Town> GetAllTowns()
 {
     return(TownRepository.GetAll());
 }