Beispiel #1
0
        public void Main(string[] args)
        {
            using (var db = new DatabaseContext())
            {
                var people = db.Person.Include(p => p.Passport);
                if(people.Count() == 0)
                {
                    SeedDatabase.Seed();
                }
            }

            var runner = new CommandRunner(serviceProvider, loggerFactory);
            runner.Run();

            Console.ReadLine();
        }
Beispiel #2
0
 internal Person RunQueryOne()
 {
     using (var db = new DatabaseContext(serviceProvider, loggerFactory))
     {
         Console.WriteLine("Running Query One");
         return db.Person.Where(p => p.Name == "Person 1")
             .Include(e => e.Passport)
             .Include(e => e.Locations)
                 .ThenInclude(l => l.Location)
                     .ThenInclude(l => l.Address)
                         .ThenInclude(a => a.Suburb)
                             .ThenInclude(s => s.State)
             .Include(e => e.Rosters)
                 .ThenInclude(r => r.Shifts)
                     .ThenInclude(t => t.ShiftStatus)
             .FirstOrDefault();
     }
 }
Beispiel #3
0
        public static void Seed()
        {
            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding States");
                db.State.AddRange(CreateStates());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding Suburbs");
                db.Suburb.AddRange(CreateSuburbs());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding Addresses");
                db.Address.AddRange(CreateAddresses());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding Locations");
                db.Location.AddRange(CreateLocations());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding People");
                db.Person.AddRange(CreatePeople());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding Rosters");
                db.Roster.AddRange(CreateRosters());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding TurnStatuses");
                db.ShiftStatus.AddRange(CreateShiftStatus());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding Turns");
                db.Shift.AddRange(CreateShifts());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Seeding Passports");
                db.Passport.AddRange(CreatePassports());
                db.SaveChanges();
            }

            using (var db = new DatabaseContext())
            {
                Console.WriteLine("Adding People Locations");
                var locations = db.Location.Where(l => l.Name == "North Pole" || l.Name == "South Pole").ToList();
                var person = db.Person.Where(p => p.Name == "Person 1").FirstOrDefault();

                foreach(var location in locations)
                {
                    person.Locations.Add(new PersonLocation()
                    {
                        Name = $"{person.Name} - {location.Name}",
                        LocationId = location.Id,
                        PersonId = person.Id
                    });
                }

                db.SaveChanges();
            }
        }