Beispiel #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new HelloHomesPersonContext(
                       serviceProvider.GetRequiredService <DbContextOptions <HelloHomesPersonContext> >()))
            {
                // Look for any Persons.
                if (context.Person.Any())
                {
                    return;   // DB has been seeded
                }

                context.Person.AddRange(
                    new Person
                {
                    IsAdmin      = true,
                    EmailAddress = "*****@*****.**",
                    Password     = PersonService.Hash("admin"),
                    FullName     = "Admin Bob",
                    PhoneNumber  = "0999"
                },

                    new Person
                {
                    IsAdmin      = false,
                    EmailAddress = "*****@*****.**",
                    Password     = PersonService.Hash("admin"),
                    FullName     = "Jim Bob",
                    PhoneNumber  = "121313"
                }
                    );
                context.SaveChanges();
            }
        }
Beispiel #2
0
        public PersonService()
        {
            var connString = Startup.personConnString;
            var options    = new DbContextOptionsBuilder <HelloHomesPersonContext>()
                             .UseSqlServer(connString)
                             .Options;

            _context = new HelloHomesPersonContext(options);
        }
Beispiel #3
0
 public PersonService(HelloHomesPersonContext context)
 {
     _context = context;
 }