public void SeedRoles(UsersRolesDbContext context)
        {
            var roles = new List <Role>
            {
                new Role
                {
                    RoleName = RoleName.Admin
                },
                new Role
                {
                    RoleName = RoleName.User
                },
                new Role
                {
                    RoleName = RoleName.Guest
                },
                new Role
                {
                    RoleName = RoleName.Test
                },
            };

            foreach (var role in roles)
            {
                Roles.Add(role.Id, role);
            }

            context.Roles.AddRange(roles);

            context.SaveChanges();
        }
        private void SeedEverything(UsersRolesDbContext context)
        {
            context.Database.EnsureCreated();

            if (context.Roles.Any())
            {
                return;
            }

            SeedRoles(context);
            SeedUsers(context);
            SeedUserRoles(context);
        }
        private void SeedUserRoles(UsersRolesDbContext context)
        {
            var userRoles = new List <UserRole>
            {
                new UserRole
                {
                    UserId = Users.Keys.ElementAt(0),
                    RoleId = Roles.Keys.ElementAt(0)
                },
                new UserRole
                {
                    UserId = Users.Keys.ElementAt(0),
                    RoleId = Roles.Keys.ElementAt(1)
                },
                new UserRole
                {
                    UserId = Users.Keys.ElementAt(1),
                    RoleId = Roles.Keys.ElementAt(2)
                },
                new UserRole
                {
                    UserId = Users.Keys.ElementAt(1),
                    RoleId = Roles.Keys.ElementAt(1)
                },
                new UserRole
                {
                    UserId = Users.Keys.ElementAt(2),
                    RoleId = Roles.Keys.ElementAt(0)
                },
                new UserRole
                {
                    UserId = Users.Keys.ElementAt(2),
                    RoleId = Roles.Keys.ElementAt(1)
                },
                new UserRole
                {
                    UserId = Users.Keys.ElementAt(2),
                    RoleId = Roles.Keys.ElementAt(2)
                },
                new UserRole
                {
                    UserId = Users.Keys.ElementAt(3),
                    RoleId = Roles.Keys.ElementAt(1)
                },
            };

            context.UserRoles.AddRange(userRoles);

            context.SaveChanges();
        }
        private void SeedUsers(UsersRolesDbContext context)
        {
            var users = new List <User>
            {
                new User
                {
                    FullName = (FullName)"Ivan Pažanin",
                    UserAvatarRelativePath = "avatar-placeholder.png",
                    MyEmail = (MyEmail)"*****@*****.**",
                },
                new User
                {
                    FullName = (FullName)"Lukas Lawrence",
                    UserAvatarRelativePath = "avatar-placeholder.png",
                    MyEmail = (MyEmail)"*****@*****.**",
                },
                new User
                {
                    FullName = (FullName)"Pedro Pascal Maxwell",
                    UserAvatarRelativePath = "avatar-placeholder.png",
                    MyEmail = (MyEmail)"*****@*****.**",
                },
                new User
                {
                    FullName = (FullName)"Nicolette Ellis",
                    UserAvatarRelativePath = "avatar-placeholder.png",
                    MyEmail = (MyEmail)"*****@*****.**",
                },
            };

            foreach (var user in users)
            {
                Users.Add(user.Id, user);
            }

            context.AddRange(users);

            context.SaveChanges();
        }
        public static void Initialize(UsersRolesDbContext context)
        {
            var initializer = new UsersRolesInitializer();

            initializer.SeedEverything(context);
        }