} // End of Initialize()

        public static void AddStudentApplications(URC_Context context, UserManager <ApplicationUser> userManager)
        {
            if (!context.Opportunities.Any() || !userManager.Users.Any())
            {
                throw new Exception("Must seed database opportunities and users before seeding student applications.");
            }

            // Early return if there are already applications
            if (context.StudentApplications.Any())
            {
                return;
            }

            // Don't need IDENTITY_INSERT because applications aren't needed for later many-to-many mappings
            context.StudentApplications.AddRange(SeedData.StudentApplications);
            context.SaveChanges();

            context.StudentCourses.AddRange(SeedData.StudentCourseMapping);
            context.SaveChanges();

            context.StudentInterests.AddRange(SeedData.StudentInterestMapping);
            context.SaveChanges();

            context.StudentSkills.AddRange(SeedData.StudentSkillMapping);
            context.SaveChanges();
        }
示例#2
0
        /// <summary>
        /// Seeds the given database with Opportunities/RequiredSkills/Tags if needed.
        /// </summary>
        /// <param name="context">The context (database) to be used.</param>
        public static void Initialize(URC_Context context)
        {
            // Look for any opportunities.
            if (context.Opportunities.Any())
            {
                return; // DB has been seeded
            }

            var opportunities = new Opportunity[]
            {
                new Opportunity {
                    ProjectName = "Artificial Muscle Polymer Experiments", ProfessorName = "professor", ProjectDescription = "Twisted coiled polymer actuators (TCPAs) are an emergent type of thermomotive artificial muscle that have recently biome-chanically surpassed human skeletal muscles (HSM). This all results in tensile contraction (TC) and Tensile Stress (TS). We are trying to optimize the polymer material properties to improve action.", ProjectImage = "uofu.jpg", ProjectMentor = "John Smith", BeginDate = DateTime.Parse("2021-03-03"), EndDate = DateTime.Parse("2021-06-03"), Pay = 20, Filled = false
                },
                new Opportunity {
                    ProjectName = "City Climate Change Research Assistant", ProfessorName = "professor_mary", ProjectDescription = "I am analyzing city climate action plans across the world and trying to find key themes, characteristics, and patterns of these climate action plans. Specifically, I will be focusing on Ho Chi Minh City, Buenos Aires, Seoul, and Mexico City, but will also be looking at other city environmental actions as needed for this project.", ProjectImage = "uofu.jpg", ProjectMentor = "Suzy Smith", BeginDate = DateTime.Parse("2021-05-10"), EndDate = DateTime.Parse("2021-10-10"), Pay = 25, Filled = false
                },
                new Opportunity {
                    ProjectName = "Multiple Computational Research Positions", ProfessorName = "Larry Longbottom", ProjectDescription = "We are looking for motivated candidates to join the Utah Waves and Architected Materials Group.", ProjectImage = "uofu.jpg", ProjectMentor = "Larry Longbottom", BeginDate = DateTime.Parse("2021-08-21"), EndDate = DateTime.Parse("2021-12-03"), Pay = 30, Filled = false
                },
                new Opportunity {
                    ProjectName = "Undergraduate Research Assistant", ProfessorName = "Oliver Olson", ProjectDescription = "Patient with acute ischemic stroke within the last 7 days will have a small blood pressure on their finger for 15 minutes.We will also use the NeurOptics NPi - 200 Pupillometer to measure each enrolled participants pupil reactivity prior to the finger blood pressure measurement.", ProjectImage = "uofu.jpg", ProjectMentor = "Bobby Joe Hill", BeginDate = DateTime.Parse("2020-12-04"), EndDate = DateTime.Parse("2021-04-03"), Pay = 10, Filled = false
                },
                new Opportunity {
                    ProjectName = "Undergrad Research Scholars - Wynne Laboratory", ProfessorName = "Jerry Wynne", ProjectDescription = "Our laboratory researches hypertension, and in particular, salt-sensitive hypertension. We investigate this from a cell/molecular basis using cell culture, microscopy and whole animal experiments. We are interested in the renal and cardiovascular physiology during hypertension, with an emphasis on inflammation.", ProjectImage = "uofu.jpg", ProjectMentor = "Bobby Joe Hill", BeginDate = DateTime.Parse("2021-04-08"), EndDate = DateTime.Parse("2021-08-04"), Pay = 20, Filled = false
                },
                new Opportunity {
                    ProjectName = "Part Time - Studying Genetic Diseases", ProfessorName = "Joe Montgomery", ProjectDescription = "I would like to mentor motivated students. Projects will depend on the previous experience of students.", ProjectImage = "uofu.jpg", ProjectMentor = "Joe Montgomery", BeginDate = DateTime.Parse("2021-06-03"), EndDate = DateTime.Parse("2021-09-03"), Pay = 10, Filled = false
                },
                new Opportunity {
                    ProjectName = "Machine Learning Based Lensless Cameras", ProfessorName = "Susan Donald", ProjectDescription = "By exploiting recent advances in machine learning, you will work in a small team to develop several uncoventional cameras. One example of a such a camera is a lensless camera that is extremely thin lightweight, yet able to perform high resolution imaging. Important applications in autonomous driving, drones, security, etc. will be explored.", ProjectImage = "uofu.jpg", ProjectMentor = "Susan Donald", BeginDate = DateTime.Parse("2021-03-03"), EndDate = DateTime.Parse("2021-06-03"), Pay = 20, Filled = false
                },
                new Opportunity {
                    ProjectName = "Wildlife Conservation Research", ProfessorName = "Jeniffer Jacobs", ProjectDescription = "The Wasatch Mountains (WM) are a stronghold for wildlife but contain the most highly recreated National Forests in the country. There is a lack of research into how wildlife are affected by human recreation, and this hampers conservation action, especially in the WM’s.", ProjectImage = "uofu.jpg", ProjectMentor = "Jeniffer Jacobs", BeginDate = DateTime.Parse("2021-03-03"), EndDate = DateTime.Parse("2021-06-03"), Pay = 20, Filled = false
                }
            };

            context.Opportunities.AddRange(opportunities);
            context.SaveChanges();

            var requiredSkills = new RequiredSkill[]
            {
                new RequiredSkill {
                    SkillName = "C#", OpportunityID = 1
                },
                new RequiredSkill {
                    SkillName = "ASP.NET Core", OpportunityID = 1
                },
                new RequiredSkill {
                    SkillName = "Entity Framework", OpportunityID = 1
                },
                new RequiredSkill {
                    SkillName = "Javascript", OpportunityID = 1
                },
                new RequiredSkill {
                    SkillName = "Java", OpportunityID = 2
                },
                new RequiredSkill {
                    SkillName = "Bootstrap", OpportunityID = 2
                },
                new RequiredSkill {
                    SkillName = "MongoDB", OpportunityID = 2
                },
                new RequiredSkill {
                    SkillName = "ElasticSearch", OpportunityID = 2
                },
                new RequiredSkill {
                    SkillName = "Python", OpportunityID = 3
                },
                new RequiredSkill {
                    SkillName = "PDB", OpportunityID = 3
                },
                new RequiredSkill {
                    SkillName = "Flask", OpportunityID = 3
                },
                new RequiredSkill {
                    SkillName = "Splunk", OpportunityID = 3
                },
                new RequiredSkill {
                    SkillName = "SQL", OpportunityID = 4
                },
                new RequiredSkill {
                    SkillName = "C", OpportunityID = 4
                },
                new RequiredSkill {
                    SkillName = "GCC", OpportunityID = 4
                },
                new RequiredSkill {
                    SkillName = "GDB", OpportunityID = 4
                },
                new RequiredSkill {
                    SkillName = "SpringBoot", OpportunityID = 5
                },
                new RequiredSkill {
                    SkillName = "Prometheus", OpportunityID = 5
                },
                new RequiredSkill {
                    SkillName = "Grafana", OpportunityID = 5
                },
                new RequiredSkill {
                    SkillName = "Alertmanager", OpportunityID = 5
                },
                new RequiredSkill {
                    SkillName = "Docker", OpportunityID = 6
                },
                new RequiredSkill {
                    SkillName = "Docker Swarm", OpportunityID = 6
                },
                new RequiredSkill {
                    SkillName = "Linux CLI", OpportunityID = 6
                },
                new RequiredSkill {
                    SkillName = "BASH", OpportunityID = 6
                },
                new RequiredSkill {
                    SkillName = "Javascript", OpportunityID = 7
                },
                new RequiredSkill {
                    SkillName = "CSS", OpportunityID = 7
                },
                new RequiredSkill {
                    SkillName = "HTML5", OpportunityID = 7
                },
                new RequiredSkill {
                    SkillName = "C#", OpportunityID = 7
                },
                new RequiredSkill {
                    SkillName = "HTML", OpportunityID = 8
                },
                new RequiredSkill {
                    SkillName = "Java", OpportunityID = 8
                },
                new RequiredSkill {
                    SkillName = "Kubernetes", OpportunityID = 8
                },
                new RequiredSkill {
                    SkillName = "Docker", OpportunityID = 8
                }
            };

            context.RequiredSkills.AddRange(requiredSkills);
            context.SaveChanges();

            // Seed Popular Student Skills
            foreach (var s in requiredSkills)
            {
                context.PopularRequiredSkills.Add(new PopularRequiredSkill {
                    name = s.SkillName.ToUpper(), count = 1
                });
            }

            var tags = new Tag[]
            {
                new Tag {
                    TagName = "Computer Science", OpportunityID = 1
                },
                new Tag {
                    TagName = "Biology", OpportunityID = 1
                },
                new Tag {
                    TagName = "Ecology", OpportunityID = 2
                },
                new Tag {
                    TagName = "Computer Science", OpportunityID = 3
                },
                new Tag {
                    TagName = "Information Systems", OpportunityID = 3
                },
                new Tag {
                    TagName = "Biochemistry", OpportunityID = 4
                },
                new Tag {
                    TagName = "Computer Networking", OpportunityID = 5
                },
                new Tag {
                    TagName = "Computer Science", OpportunityID = 5
                },
                new Tag {
                    TagName = "Biology", OpportunityID = 6
                },
                new Tag {
                    TagName = "Genetics", OpportunityID = 6
                },
                new Tag {
                    TagName = "Machine Learning", OpportunityID = 7
                },
                new Tag {
                    TagName = "Computer Science", OpportunityID = 7
                },
                new Tag {
                    TagName = "Biology", OpportunityID = 8
                },
                new Tag {
                    TagName = "Ecology", OpportunityID = 8
                }
            };

            context.Tags.AddRange(tags);
            context.SaveChanges();
        }
        public static void Initialize(URC_Context context)
        {
            context.Database.EnsureCreated();

            // Early return if there are any opportunities already
            if (context.Opportunities.Any())
            {
                return;
            }

            // Thanks https://stackoverflow.com/questions/13086006/how-can-i-force-entity-framework-to-insert-identity-columns
            // No thanks to EF not recognizing the SET IDENTITY_INSERT except when using raw SQL
            // There are likely more advanced ways to seed the database that are less brittle

            // Seed courses
            var transaction = context.Database.BeginTransaction();

            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Courses] ON;");
            foreach (var course in SeedData.Courses)
            {
                context.Database.ExecuteSqlInterpolated($"INSERT INTO Courses (CourseId, Name) VALUES ({course.CourseId}, {course.Name});");
            }
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Courses] OFF;");
            context.SaveChanges();
            transaction.Commit();

            // Seed interests
            transaction = context.Database.BeginTransaction();
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Interests] ON;");
            foreach (var interest in SeedData.Interests)
            {
                context.Database.ExecuteSqlInterpolated($"INSERT INTO Interests (InterestId, Name) VALUES ({interest.InterestId}, {interest.Name});");
            }
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Interests] OFF;");
            context.SaveChanges();
            transaction.Commit();

            // Seed skills
            transaction = context.Database.BeginTransaction();
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Skills] ON;");
            foreach (var skill in SeedData.Skills)
            {
                context.Database.ExecuteSqlInterpolated($"INSERT INTO Skills (SkillId, Name) VALUES ({skill.SkillId}, {skill.Name});");
            }
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Skills] OFF;");
            context.SaveChanges();
            transaction.Commit();

            // Seed opportunity search tags
            transaction = context.Database.BeginTransaction();
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[SearchTags] ON;");
            foreach (var tag in SeedData.SearchTags)
            {
                context.Database.ExecuteSqlInterpolated($"INSERT INTO SearchTags (SearchTagId, Name) VALUES ({tag.SearchTagId}, {tag.Name});");
            }
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[SearchTags] OFF;");
            context.SaveChanges();
            transaction.Commit();

            // Seed extended user models
            // which do not require IDENTITY_INSERT for some unknown reason
            context.Students.AddRange(SeedData.Students);
            context.Professors.AddRange(SeedData.Professors);
            context.SaveChanges();

            // Seed opportunities
            transaction = context.Database.BeginTransaction();
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Opportunities] ON;");
            foreach (var opp in SeedData.Opportunities)
            {
                // Thanks https://stackoverflow.com/questions/31764898/long-string-interpolation-lines-in-c6
                // datetime2 format https://docs.microsoft.com/en-us/sql/t-sql/data-types/datetime2-transact-sql?view=sql-server-ver15
                // format date https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
                context.Database.ExecuteSqlInterpolated(
                    $@"INSERT INTO Opportunities (OpportunityId, ProfessorId, Name, Description, RoleDescription, Responsibilities, Mentor, PostedDate, Deadline, Pay, IsFilled) VALUES ({opp.OpportunityId}, {opp.Professor.ProfessorId}, {opp.Name}, {opp.Description}, {opp.RoleDescription}, {opp.Responsibilities}, {opp.Mentor}, {opp.PostedDate.ToShortDateString()}, {opp.Deadline.ToShortDateString()}, {opp.Pay}, {opp.IsFilled});"
                    );
            }
            context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Opportunities] OFF;");
            context.SaveChanges();
            transaction.Commit();

            // Mappings
            context.OpportunitySearchTags.AddRange(SeedData.OpportunitySearchTagMapping);
            context.SaveChanges();

            context.OpportunityRequiredSkills.AddRange(SeedData.OpportunityRequiredSkillMapping);
            context.SaveChanges();

            context.OpportunityPreferredSkills.AddRange(SeedData.OpportunityPreferredSkillMapping);
            context.SaveChanges();


            // seeding for counter by Ping
            context.OpportunityCounters.AddRange(SeedData.OpportunityCounterMapping);
            context.SaveChanges();


            // seeding for visitor counter  by Ping
            context.GeneralInfos.AddRange(SeedData.GeneralInfo);
            context.SaveChanges();
        } // End of Initialize()
示例#4
0
        /// <summary>
        /// Seeds the given database with Student/StudentSkill/CompletedCourses if needed.
        /// </summary>
        /// <param name="context">The context (database) to be used.</param>
        public static void Initialize(URC_Context context, UserManager <URCUser> userManager)
        {
            // Look for any student aplications.
            if (context.Students.Any())
            {
                return; // DB has been seeded
            }

            var sid1 = userManager.FindByEmailAsync("*****@*****.**").Result.Id.ToString();
            var sid2 = userManager.FindByEmailAsync("*****@*****.**").Result.Id.ToString();
            var studentApplications = new Student[]
            {
                new Student {
                    Sid = sid2, StudentName = "Ashley Eaton", ExpectedGraduationDate = DateTime.Parse("2022-05-10"), DegreePlan = "CE", GPA = (float)3.9, Uid = "u0000002", AvailableHoursPerWeek = 10, PersonalStatement = "Hi, I would like to be considered for a research position. I believe that I will be a great addition to any team. I am a really good student.", ProfileCreationDate = DateTime.Parse("2020-10-11"), Active = true
                },
                new Student {
                    Sid = sid1, StudentName = "Oliver Allphin", ExpectedGraduationDate = DateTime.Parse("2021-05-10"), DegreePlan = "CS", GPA = (float)3.7, Uid = "u0000001", AvailableHoursPerWeek = 20, PersonalStatement = "This is my personal statement. I am a great student and am very interested in research. Please consider me! This is my personal statement. I am a great student and am very interested in research. Please consider me! This is my personal statement. I am a great student and am very interested in research. Please consider me!", ProfileCreationDate = DateTime.Parse("2020-10-10"), Active = true
                }
            };

            context.Students.AddRange(studentApplications);
            context.SaveChanges();

            var studentSkills = new StudentSkill[]
            {
                new StudentSkill {
                    SkillName = "C#", StudentID = 1
                },
                new StudentSkill {
                    SkillName = "ASP.NET Core", StudentID = 1
                },
                new StudentSkill {
                    SkillName = "Entity Framework", StudentID = 1
                },
                new StudentSkill {
                    SkillName = "Javascript", StudentID = 1
                },
                new StudentSkill {
                    SkillName = "HTML", StudentID = 1
                },
                new StudentSkill {
                    SkillName = "Java", StudentID = 2
                },
                new StudentSkill {
                    SkillName = "Bootstrap", StudentID = 2
                },
                new StudentSkill {
                    SkillName = "MongoDB", StudentID = 2
                },
                new StudentSkill {
                    SkillName = "ElasticSearch", StudentID = 2
                }
            };

            context.StudentSkills.AddRange(studentSkills);
            context.SaveChanges();

            // Seed Popular Student Skills
            foreach (var s in studentSkills)
            {
                context.PopularStudentSkills.Add(new PopularStudentSkill {
                    name = s.SkillName.ToUpper(), count = 1
                });
            }

            context.SaveChanges();
            var interests = new Interest[]
            {
                new Interest {
                    InterestName = "Basketball", StudentID = 1
                },
                new Interest {
                    InterestName = "Snowboarding", StudentID = 1
                },
                new Interest {
                    InterestName = "Web Software Architecture", StudentID = 1
                },
                new Interest {
                    InterestName = "Wake Boarding", StudentID = 1
                },
                new Interest {
                    InterestName = "Art", StudentID = 2
                },
                new Interest {
                    InterestName = "Piano", StudentID = 2
                },
                new Interest {
                    InterestName = "Rock Climbing", StudentID = 2
                },
                new Interest {
                    InterestName = "Chess", StudentID = 2
                }
            };

            context.Interests.AddRange(interests);
            context.SaveChanges();

            var completedCourses = new CompletedCourse[]
            {
                new CompletedCourse {
                    CompletedCourseName = "CS-3100", StudentID = 1
                },
                new CompletedCourse {
                    CompletedCourseName = "CS-2420", StudentID = 1
                },
                new CompletedCourse {
                    CompletedCourseName = "CS-4480", StudentID = 1
                },
                new CompletedCourse {
                    CompletedCourseName = "CS-3505", StudentID = 1
                },
                new CompletedCourse {
                    CompletedCourseName = "CS-2420", StudentID = 2
                },
                new CompletedCourse {
                    CompletedCourseName = "CS-1030", StudentID = 2
                },
                new CompletedCourse {
                    CompletedCourseName = "CS-1410", StudentID = 2
                },
                new CompletedCourse {
                    CompletedCourseName = "MATH-2270", StudentID = 2
                }
            };

            context.CompletedCourses.AddRange(completedCourses);
            context.SaveChanges();
        }