Exemplo n.º 1
0
        public void SeedEverything(PGPDbContext context)
        {
            context.Database.EnsureCreated();

            if (!context.Roles.Any())
            {
                SeedRoles(context);
            }

            if (!context.Categories.Any())
            {
                SeedCategories(context);
            }

            if (!context.Users.Any())
            {
                SeedUsers(context);
            }

            if (!context.Pets.Any())
            {
                SeedPets(context);
            }

            if (!context.Comments.Any())
            {
                SeedComments(context);
            }
        }
Exemplo n.º 2
0
        private void SeedPets(PGPDbContext context)
        {
            var pets = new[]
            {
                new Pet
                {
                    Name         = "Reksas",
                    Age          = 5,
                    Gender       = Gender.Male,
                    Weight       = 30,
                    Height       = 5.4,
                    IsSterilized = true,
                    Description  = "Kažkoks aprašymas",
                    DateAdded    = DateTime.Now,
                    State        = State.NotGivenAway,
                    CategoryId   = 1,
                    UserId       = 4
                },
                new Pet
                {
                    Name         = "Murkis",
                    Age          = 3,
                    Gender       = Gender.Male,
                    Weight       = 30,
                    Height       = 3.4,
                    IsSterilized = true,
                    Description  = "Kažkoks aprašymas",
                    DateAdded    = DateTime.Now,
                    State        = State.NotGivenAway,
                    CategoryId   = 2,
                    UserId       = 4
                },
                new Pet
                {
                    Name         = "Peksas",
                    Age          = 4,
                    Gender       = Gender.Male,
                    Weight       = 30,
                    Height       = 3.4,
                    IsSterilized = true,
                    Description  = "Kažkoks aprašymas",
                    DateAdded    = DateTime.Now,
                    State        = State.NotGivenAway,
                    CategoryId   = 2,
                    UserId       = 4
                }
            };

            context.Pets.AddRange(pets);

            context.SaveChanges();
        }
Exemplo n.º 3
0
        private void SeedUsers(PGPDbContext context)
        {
            var users = new[]
            {
                new User
                {
                    Email       = "*****@*****.**",
                    Password    = "******",
                    PhoneNumber = "8654442121",
                    FirstName   = "Petras",
                    LastName    = "Petraitis",
                    RoleId      = 2
                },
                new User
                {
                    Email       = "*****@*****.**",
                    Password    = "******",
                    PhoneNumber = "8653332121",
                    FirstName   = "Jonas",
                    LastName    = "Jonaitis",
                    RoleId      = 3
                },
                new User
                {
                    Email       = "*****@*****.**",
                    Password    = "******",
                    PhoneNumber = "8652222121",
                    FirstName   = "Paulius",
                    LastName    = "Paulauskas",
                    RoleId      = 1
                },
                new User
                {
                    Email       = "*****@*****.**",
                    Password    = "******",
                    PhoneNumber = "8651112121",
                    FirstName   = "Admin",
                    LastName    = "Admin",
                    RoleId      = 3
                },
            };

            context.Users.AddRange(users);

            context.SaveChanges();
        }
Exemplo n.º 4
0
        private void SeedCategories(PGPDbContext context)
        {
            var categories = new[]
            {
                new Category {
                    Title = "Dogs"
                },
                new Category {
                    Title = "Cats"
                },
                new Category {
                    Title = "Others"
                }
            };

            context.Categories.AddRange(categories);

            context.SaveChanges();
        }
Exemplo n.º 5
0
        private void SeedRoles(PGPDbContext context)
        {
            var roles = new[]
            {
                new Role {
                    Title = "User"
                },
                new Role {
                    Title = "Moderator"
                },
                new Role {
                    Title = "Admin"
                }
            };

            context.Roles.AddRange(roles);

            context.SaveChanges();
        }
Exemplo n.º 6
0
        private void SeedComments(PGPDbContext context)
        {
            var comments = new[]
            {
                new Comment
                {
                    Text            = "Pirmas komentaras",
                    CreatedAt       = DateTime.Now,
                    CreatedByUserId = 4,
                    PetId           = 1
                },
                new Comment
                {
                    Text            = "Antras komentaras",
                    CreatedAt       = DateTime.Now,
                    CreatedByUserId = 4,
                    PetId           = 1
                },
                new Comment
                {
                    Text            = "Kažkoks komentaras",
                    CreatedAt       = DateTime.Now,
                    CreatedByUserId = 2,
                    PetId           = 1
                },
                new Comment
                {
                    Text            = "Komentaras",
                    CreatedAt       = DateTime.Now,
                    CreatedByUserId = 4,
                    PetId           = 2
                }
            };

            context.Comments.AddRange(comments);

            context.SaveChanges();
        }
Exemplo n.º 7
0
        public static void Initialize(PGPDbContext context)
        {
            var initializer = new PGPInitializer();

            initializer.SeedEverything(context);
        }