public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new PMContext(serviceProvider.GetRequiredService <DbContextOptions <PMContext> >()))
            {
                if (!context.Projects.Any())
                {
                    context.Projects.AddRange(
                        new Project {
                        ID = 1, Name = "Project1", Detail = "test project 1", CreatedOn = DateTime.Today
                    },
                        new Project {
                        ID = 2, Name = "Project2", Detail = "test project 2", CreatedOn = DateTime.Today
                    },
                        new Project {
                        ID = 3, Name = "Project3", Detail = "test project 3", CreatedOn = DateTime.Today
                    },
                        new Project {
                        ID = 4, Name = "Project4", Detail = "test project 4", CreatedOn = DateTime.Today
                    },
                        new Project {
                        ID = 5, Name = "Project5", Detail = "test project 5", CreatedOn = DateTime.Today
                    },
                        new Project {
                        ID = 6, Name = "Project6", Detail = "test project 6", CreatedOn = DateTime.Today
                    });
                    context.SaveChanges();
                }

                if (!context.Tasks.Any())
                {
                    context.Tasks.AddRange(new Tasks {
                        ID = 1, ProjectID = 1, Status = TaskStatus.InProgress, AssignedToUserID = 1, Detail = "test task assigned to user 1 and project 1", CreatedOn = DateTime.Today
                    },
                                           new Tasks {
                        ID = 2, ProjectID = 2, Status = TaskStatus.QA, AssignedToUserID = 2, Detail = "test task assigned to user 2 and project 2", CreatedOn = DateTime.Today
                    },
                                           new Tasks {
                        ID = 3, ProjectID = 2, Status = TaskStatus.Completed, AssignedToUserID = 2, Detail = "test task assigned to user 2 and project 2", CreatedOn = DateTime.Today
                    });
                    context.SaveChanges();
                }

                if (!context.Users.Any())
                {
                    context.Users.AddRange(new User {
                        ID = 1, FirstName = "kiran", LastName = "kumar", Email = "*****@*****.**", Password = "******"
                    },
                                           new User {
                        ID = 2, FirstName = "Naveen", LastName = "Kumar", Email = "*****@*****.**", Password = "******"
                    },
                                           new User {
                        ID = 3, FirstName = "Arun", LastName = "Kumar", Email = "*****@*****.**", Password = "******"
                    },
                                           new User {
                        ID = 4, FirstName = "Ravi", LastName = "Kumar", Email = "*****@*****.**", Password = "******"
                    },
                                           new User {
                        ID = 5, FirstName = "Sunil", LastName = "Kumar", Email = "*****@*****.**", Password = "******"
                    },
                                           new User {
                        ID = 6, FirstName = "Vijay", LastName = "Kumar", Email = "*****@*****.**", Password = "******"
                    });
                    context.SaveChanges();
                }
            }
        }
예제 #2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new PMContext(serviceProvider.GetRequiredService <DbContextOptions <PMContext> >()))
            {
                if (!context.Projects.Any())
                {
                    context.Projects.AddRange(
                        new Project
                    {
                        ID        = 1,
                        Name      = "TestProject1",
                        Detail    = "This is a test project",
                        CreatedOn = DateTime.Today
                    },
                        new Project
                    {
                        ID        = 2,
                        Name      = "TestProject2",
                        Detail    = "This is a test project",
                        CreatedOn = DateTime.Today
                    },
                        new Project
                    {
                        ID        = 3,
                        Name      = "TestProject3",
                        Detail    = "This is a test project",
                        CreatedOn = DateTime.Today
                    },
                        new Project
                    {
                        ID        = 4,
                        Name      = "TestProject4",
                        Detail    = "This is a test project",
                        CreatedOn = DateTime.Today
                    });
                    context.SaveChanges();
                }

                if (!context.Tasks.Any())
                {
                    context.Tasks.AddRange(new Task
                    {
                        ID               = 1,
                        ProjectID        = 1,
                        Status           = TaskStatus.InProgress,
                        AssignedToUserID = 1,
                        Detail           = "This is a test task",
                        CreatedOn        = DateTime.Today
                    },
                                           new Task
                    {
                        ID               = 2,
                        ProjectID        = 1,
                        Status           = TaskStatus.QA,
                        AssignedToUserID = 2,
                        Detail           = "This is a test task",
                        CreatedOn        = DateTime.Today
                    },
                                           new Task
                    {
                        ID               = 3,
                        ProjectID        = 2,
                        Status           = TaskStatus.Completed,
                        AssignedToUserID = 2,
                        Detail           = "This is a test task",
                        CreatedOn        = DateTime.Today
                    });
                    context.SaveChanges();
                }

                if (!context.Users.Any())
                {
                    context.Users.AddRange(new User
                    {
                        ID        = 1,
                        FirstName = "John",
                        LastName  = "Doe",
                        Username  = "******",
                    },
                                           new User
                    {
                        ID        = 2,
                        FirstName = "John",
                        LastName  = "Skeet",
                        Username  = "******"
                    },
                                           new User
                    {
                        ID        = 3,
                        FirstName = "Mark",
                        LastName  = "Seeman",
                        Username  = "******",
                    },
                                           new User
                    {
                        ID        = 4,
                        FirstName = "Bob",
                        LastName  = "Martin",
                        Username  = "******",
                    });
                    context.SaveChanges();
                }
            }
        }