예제 #1
0
        public void Exercise5()
        {
            CountryRepository countryRepository = new CountryRepository();
            TownRepository    townRepository    = new TownRepository();

            foreach (var item in countryRepository.GetAll())
            {
                Console.WriteLine(item.Name);
            }
            Console.WriteLine("Enter Country Name => ");
            string             countryName = Convert.ToString(Console.ReadLine());
            Country            country     = countryRepository.GetByName(countryName);
            IEnumerable <Town> towns       = townRepository.GetAllByCountry(country);
            List <Town>        townList    = new List <Town>(towns);

            if (townList.Count == 0)
            {
                Console.WriteLine("No town names were affected.");
                return;
            }
            Console.WriteLine(townList.Count + "town names were affected. ");
            foreach (var item in towns)
            {
                item.Name = item.Name.ToUpper();
                townRepository.Update(item);
                Console.Write(item.Name + ",");
            }
            Console.WriteLine();
        }
예제 #2
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();
        }
예제 #3
0
 public UnitOfWork()
 {
     Items     = new ItemRepository();
     Merchants = new MerchantRepository();
     Monsters  = new MonsterRepository();
     Routes    = new RouteRepository();
     Towns     = new TownRepository();
     Elements  = new ElementRepository();
 }
예제 #4
0
        static void Main()
        {
            ITownRepository townRepository = new TownRepository();

            townRepository.SelectListData();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }
예제 #5
0
 private static Town GetTownById(int id)
 {
     return(TownRepository.GetById(id));
 }
예제 #6
0
 private static IEnumerable <Town> GetAllTowns()
 {
     return(TownRepository.GetAll());
 }