Пример #1
0
        public static void Initialize(DpContext context)
        {
            if (!context.Roles.Any(r => r.Name == "AppAdmin"))
            {
                var store   = new DpRoleStore(context);
                var manager = new DpRoleManager(store);
                var role    = new Role()
                {
                    Name = "AppAdmin"
                };

                manager.Create(role);
            }

            if (!context.Users.Any(u => u.UserName == "founder"))
            {
                var store   = new DpUserStore(context);
                var manager = new DpUserManager(store);
                var user    = new User {
                    UserName = "******"
                };

                manager.Create(user, "Password1!");
                manager.AddToRole(user.Id, "AppAdmin");
            }
            // Look for any students.
            if (context.Projects.Any())
            {
                return;   // DB has been seeded
            }

            context.Projects.Add(
                new Project
            {
                Name            = "Project 1",
                Description     = "Project 1 Description",
                CreatedDateTime = DateTime.Parse("2000-01-01"),
                TaskItems       = new[]
                {
                    new TaskItem {
                        Name = "Task1", Description = "Task 1 Description", CreatedDateTime = DateTime.Parse("2005-09-01"), IsActive = true, ProjectId = 1
                    },
                    new TaskItem {
                        Name = "Task2", Description = "Task 2 Description", CreatedDateTime = DateTime.Parse("2015-11-15"), IsActive = true, ProjectId = 1
                    },
                    new TaskItem {
                        Name = "Task3", Description = "Task 3 Description", CreatedDateTime = DateTime.Parse("2016-09-12"), IsActive = true, ProjectId = 1
                    },
                    new TaskItem {
                        Name = "Task4", Description = "Task 4 Description", CreatedDateTime = DateTime.Parse("2004-01-12"), IsActive = true, ProjectId = 1
                    }
                }
            });

            context.SaveChanges();
        }
Пример #2
0
 public DpUserStore(DpContext context)
     : base(context)
 {
 }
Пример #3
0
 public AuthRepository()
 {
     _ctx         = new DpContext();
     _userManager = new DpUserManager(new DpUserStore(_ctx));
 }
Пример #4
0
 public DpRoleStore(DpContext context)
     : base(context)
 {
 }