Ejemplo n.º 1
0
        internal static void SeedAdmin(VoiceWallDbContext context)
        {
            const string AdminEmail    = "*****@*****.**";
            const string AdminPassword = "******";

            if (context.Users.Any(u => u.Email == AdminEmail))
            {
                return;
            }

            var userManager = new UserManager <User>(new UserStore <User>(context));

            var admin = new User
            {
                FirstName = "Pesho",
                LastName  = "Admina",
                Email     = AdminEmail,
                UserName  = AdminEmail,
                UserImage = GlobalConstants.DefaultUserPicture
            };

            userManager.Create(admin, AdminPassword);
            userManager.AddToRole(admin.Id, GlobalConstants.AdminRole);
            userManager.AddToRole(admin.Id, GlobalConstants.ModeratorRole);
            userManager.AddToRole(admin.Id, GlobalConstants.DefaultRole);

            context.SaveChanges();
        }
Ejemplo n.º 2
0
        internal static void SeedUsers(VoiceWallDbContext context)
        {
            var names = GetUserNames();

            var profilePictures = GetProfileImages();

            var userManager = new UserManager <User>(new UserStore <User>(context));

            for (int i = 0; i < Math.Min(names.Length, profilePictures.Length); i++)
            {
                var user = new User()
                {
                    UserName  = string.Format("FakeUser{0}", i + 1),
                    Email     = string.Format("FakeUser{0}@FakeEmail.com", i + 1),
                    FirstName = names[i].Substring(0, names[i].IndexOf(" ")),
                    LastName  = names[i].Substring(names[i].IndexOf(" ") + 1),
                    UserImage = profilePictures[i]
                };

                userManager.Create(user, "qwerty");

                userManager.AddToRole(user.Id, GlobalConstants.DefaultRole);

                context.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        internal static void SeedModerator(VoiceWallDbContext context)
        {
            const string ModeratorEmail    = "*****@*****.**";
            const string ModeratorPassword = "******";

            if (context.Users.Any(u => u.Email == ModeratorEmail))
            {
                return;
            }

            var userManager = new UserManager <User>(new UserStore <User>(context));

            var admin = new User
            {
                FirstName = "Gosho",
                LastName  = "Moderatora",
                Email     = ModeratorEmail,
                UserName  = ModeratorEmail,
                UserImage = GlobalConstants.DefaultUserPicture
            };

            userManager.Create(admin, ModeratorPassword);

            userManager.AddToRole(admin.Id, GlobalConstants.ModeratorRole);
            userManager.AddToRole(admin.Id, GlobalConstants.DefaultRole);

            context.SaveChanges();
        }
Ejemplo n.º 4
0
        internal static void SeedData(VoiceWallDbContext context)
        {
            var userIds = context.Users.Select(u => u.Id).ToArray();

            for (int i = 0; i < 50; i++)
            {
                var t = random.Next(0, 100) > 50 ? ContentType.Picture : random.Next(0, 100) > 50 ? ContentType.Sound : ContentType.Video;
                var u = t == ContentType.Picture ? GetImageUrl() : t == ContentType.Sound ? GetSoundUrl() : GetVideoUrl();

                context.Contents.Add(new Content()
                {
                    ContentType  = t,
                    ContentUrl   = u,
                    UserId       = userIds[random.Next(0, userIds.Length)],
                    ContentViews = new List <ContentView>()
                    {
                        new ContentView()
                        {
                            Liked = true, UserId = userIds[random.Next(0, userIds.Length)]
                        },
                        new ContentView()
                        {
                            Liked = true, UserId = userIds[random.Next(0, userIds.Length)]
                        },
                        new ContentView()
                        {
                            Liked = true, UserId = userIds[random.Next(0, userIds.Length)]
                        },
                        new ContentView()
                        {
                            Liked = false, UserId = userIds[random.Next(0, userIds.Length)]
                        },
                        new ContentView()
                        {
                            Liked = null, UserId = userIds[random.Next(0, userIds.Length)]
                        },
                    },
                    Comments = GetComments(userIds)
                });

                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        internal static void SeedJokes(VoiceWallDbContext context)
        {
            if (context.Jokes.Any())
            {
                return;
            }

            var allJokes = GetAllJokes();

            foreach (var joke in allJokes)
            {
                context.Jokes.Add(new Joke()
                {
                    Text = joke
                });
            }

            context.SaveChanges();
        }
Ejemplo n.º 6
0
        internal static void SeedRoles(VoiceWallDbContext context)
        {
            if (context.Roles.Any())
            {
                return;
            }

            var roleStore   = new RoleStore <IdentityRole>(context);
            var roleManager = new RoleManager <IdentityRole>(roleStore);

            roleManager.Create(new IdentityRole {
                Name = GlobalConstants.DefaultRole
            });
            roleManager.Create(new IdentityRole {
                Name = GlobalConstants.AdminRole
            });
            roleManager.Create(new IdentityRole {
                Name = GlobalConstants.ModeratorRole
            });

            context.SaveChanges();
        }