public static void Initialise(IServiceProvider serviceProvider)
        {
            using (var context = new RoomBookingsContext(serviceProvider.GetRequiredService <DbContextOptions <RoomBookingsContext> >()))
            {
                if (context.RoomTimes.Any())
                {
                    return;
                }

                context.RoomTimes.AddRange(
                    new RoomTime {
                    Id = 1, RoomId = 1, StartTime = new TimeSpan(8), EndTime = new TimeSpan(18)
                },
                    new RoomTime {
                    Id = 1, RoomId = 2, StartTime = new TimeSpan(0, 0, 7, 5), EndTime = new TimeSpan(18)
                },
                    new RoomTime {
                    Id = 1, RoomId = 3, StartTime = new TimeSpan(8), EndTime = new TimeSpan(16)
                },
                    new RoomTime {
                    Id = 1, RoomId = 4, StartTime = new TimeSpan(8), EndTime = new TimeSpan(18)
                }
                    );

                context.SaveChanges();
            }
        }
        public static void Initialise(IServiceProvider serviceProvider)
        {
            using (var context = new RoomBookingsContext(serviceProvider.GetRequiredService <DbContextOptions <RoomBookingsContext> >()))
            {
                if (context.People.Any())
                {
                    return;
                }

                context.People.AddRange(
                    new Person {
                    Id = 1, Name = "John Smith", DateOfBirth = new DateTime(2000, 12, 1, 12, 0, 0)
                },
                    new Person {
                    Id = 2, Name = "Jane Doe", DateOfBirth = new DateTime(1965, 12, 1, 12, 0, 0)
                },
                    new Person {
                    Id = 3, Name = "Jack Jones", DateOfBirth = new DateTime(1972, 12, 1, 12, 0, 0)
                },
                    new Person {
                    Id = 4, Name = "Mary Murphy", DateOfBirth = new DateTime(2001, 12, 1, 12, 0, 0)
                },
                    new Person {
                    Id = 5, Name = "Bob Trent", DateOfBirth = new DateTime(1983, 12, 1, 12, 0, 0)
                },
                    new Person {
                    Id = 6, Name = "John Smith", DateOfBirth = new DateTime(1999, 12, 1, 12, 0, 0)
                }
                    );

                context.SaveChanges();
            }
        }
Esempio n. 3
0
        public static void Initialise(IServiceProvider serviceProvider)
        {
            using (var context = new RoomBookingsContext(serviceProvider.GetRequiredService <DbContextOptions <RoomBookingsContext> >()))
            {
                if (context.Rooms.Any())
                {
                    return;
                }

                context.Rooms.AddRange(
                    new Room {
                    Id = 1, Name = "Room One"
                },
                    new Room {
                    Id = 2, Name = "Room Three"
                },
                    new Room {
                    Id = 3, Name = "Room Two"
                },
                    new Room {
                    Id = 4, Name = "Room Four"
                }
                    );

                context.SaveChanges();

                var roomTwo   = context.Rooms.FirstOrDefault(f => f.Id == 2);
                var roomThree = context.Rooms.FirstOrDefault(f => f.Id == 3);

                context.RoomBookings.AddRange(
                    new RoomBooking {
                    Id = 1, PersonId = 6, Room = roomTwo, StartTime = new DateTime(2021, 05, 20, 9, 45, 0), EndTime = new DateTime(2021, 05, 20, 10, 00, 0)
                },
                    new RoomBooking {
                    Id = 2, PersonId = 4, Room = roomThree, StartTime = new DateTime(2021, 05, 20, 10, 15, 0), EndTime = new DateTime(2021, 05, 20, 11, 15, 0)
                },
                    new RoomBooking {
                    Id = 3, PersonId = 1, Room = roomThree, StartTime = new DateTime(2021, 05, 20, 9, 00, 0), EndTime = new DateTime(2021, 05, 20, 10, 00, 0)
                }

                    );

                context.SaveChanges();
            }
        }