Пример #1
0
        public static void EnsurePopulated(IApplicationBuilder application)
        {
            AppointmentsContext context = application.ApplicationServices.
                                          CreateScope().ServiceProvider.GetRequiredService <AppointmentsContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }

            if (!context.Appointments.Any())
            {
                context.Appointments.AddRange(

                    new Appointment
                {
                    GroupName  = "Smith Group",
                    GroupSize  = 4,
                    GroupEmail = "*****@*****.**",
                    ApptTime   = new DateTime(2021, 05, 01)
                },

                    new Appointment
                {
                    GroupName  = "Johnson Group",
                    GroupSize  = 4,
                    GroupEmail = "*****@*****.**",
                    ApptTime   = new DateTime(2021, 05, 02),
                },

                    new Appointment
                {
                    GroupName  = "Thomas Group",
                    GroupSize  = 2,
                    GroupEmail = "*****@*****.**",
                    ApptTime   = new DateTime(2021, 05, 03),
                },

                    new Appointment
                {
                    GroupName  = "Larry Group",
                    GroupSize  = 3,
                    GroupEmail = "*****@*****.**",
                    ApptTime   = new DateTime(2021, 05, 04),
                },

                    new Appointment
                {
                    GroupName  = "Sally Group",
                    GroupSize  = 8,
                    GroupEmail = "*****@*****.**",
                    ApptTime   = new DateTime(2021, 05, 05),
                },

                    new Appointment
                {
                    GroupName  = "Sam Group",
                    GroupSize  = 1,
                    GroupEmail = "*****@*****.**",
                    ApptTime   = new DateTime(2021, 05, 06),
                }
                    );

                //save all changes
                context.SaveChanges();
            }
        }
Пример #2
0
 //constructor
 public EFAppointmentRepository(AppointmentsContext context)
 {
     _context = context;
 }