Пример #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new TodoDbContext(serviceProvider.GetRequiredService <DbContextOptions <TodoDbContext> >()))
            {
                // Look for any movies.
                if (context.TodoItem.Any())
                {
                    return; // DB table has been seeded
                }

                context.TodoItem.AddRange(
                    new TodoItem
                {
                    Title       = "Item 1",
                    Description = "Description 1",
                    AddedAt     = DateTime.Now,
                    Deadline    = DateTimeOffset.Now,
                    Importance  = Importance.Low,
                    State       = State.InProgress,
                    ClosedAt    = DateTime.Now
                },

                    new TodoItem
                {
                    Title       = "Item 2",
                    Description = "Description 2",
                    AddedAt     = DateTime.Now,
                    Deadline    = DateTimeOffset.Now,
                    Importance  = Importance.Low,
                    State       = State.InProgress,
                    ClosedAt    = DateTime.Now
                }

                    );
                context.SaveChanges();
            }
        }
Пример #2
0
 public DbService(TodoDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Пример #3
0
 public IndexModel(TodoApp.Data.TodoDbContext context)
 {
     _context = context;
 }