示例#1
0
 public async Task Initialize(IDatabaseFiller dbFiller)
 {
     if (!Universities.Any() && !Faculties.Any() && !Programmes.Any())
     {
         DataFixture.Initialize(this);
         await dbFiller.Fill(this);
     }
 }
示例#2
0
        public void Seed()
        {
            if (!Faculties.Any())
            {
                Faculties.Add(new Faculty {
                    Name = "FNWI"
                });
                SaveChanges();
            }

            if (!SecurityQuestions.Any())
            {
                List <SecurityQuestions> questions = new List <SecurityQuestions>();
                void AddQuestion(string text, DeviceType mask)
                {
                    questions.Add(new Data.SecurityQuestions()
                    {
                        Text = text,
                        Mask = mask,
                    });
                }

                AddQuestion("Does the device have encrypted storage?", DeviceType.All);
                AddQuestion("Are local accounts only accessible with strong passwords?", DeviceType.All);
                AddQuestion("Does the device have a strong access code(minimum 6 characters) other than the SIM card PIN code?", DeviceType.Mobile | DeviceType.Tablet);
                AddQuestion("The OS and all applications are maintained by a supplier or community, and are up to date including security updates.", DeviceType.All);
                AddQuestion("Applicable anti malware and antivirus solutions are present, active and up to date.", DeviceType.All);
                AddQuestion("Local (application) firewall is active and alerts the user to unusual behaviour.", DeviceType.Desktop | DeviceType.Laptop);
                AddQuestion("Laptop or desktop should be automatically locked after a pre-set period of inactivity after a maximum of 15 minutes and phones or tablets after 5 minutes.", DeviceType.Desktop | DeviceType.Laptop);
                AddQuestion("Remote wipe, lock, or effective data protection measures to prevent loss of setting information in the event of theft should be in place.", DeviceType.All);
                SecurityQuestions.AddRange(questions);
                SaveChanges();
            }

            int facultyId = Faculties.First(f => f.Name == "FNWI").Id;
            var userIds   = new string[] { User.ImporterId, User.IntuneServiceId, User.LabnetId, User.ExpireId };

            foreach (string id in userIds)
            {
                if (!Users.Any(u => u.UserName == id))
                {
                    Users.Add(new User()
                    {
                        Name      = id,
                        UserName  = id,
                        FacultyId = facultyId,
                        Email     = "*****@*****.**",
                    });
                    SaveChanges();
                }
            }
        }
示例#3
0
        public async Task InitializeDb()
        {
            await Database.EnsureCreatedAsync();

            if (Students.Any() || Groups.Any() || Faculties.Any())
            {
                return;
            }

            await using var transaction = await Database.BeginTransactionAsync();

            try
            {
                var students = new[]
                {
                    new Student {
                        Email = "*****@*****.**", Name = "StudentName1", Surname = "StudentSurname1"
                    },
                    new Student {
                        Email = "*****@*****.**", Name = "StudentName2", Surname = "StudentSurname2"
                    },
                    new Student {
                        Email = "*****@*****.**", Name = "StudentName3", Surname = "StudentSurname3"
                    },
                    new Student {
                        Email = "*****@*****.**", Name = "StudentName4", Surname = "StudentSurname4"
                    },
                    new Student {
                        Email = "*****@*****.**", Name = "StudentName5", Surname = "StudentSurname5"
                    },
                    new Student {
                        Email = "*****@*****.**", Name = "StudentName6", Surname = "StudentSurname6"
                    }
                };
                await Students.AddRangeAsync(students);
                await SaveChangesAsync();

                var groups = new[]
                {
                    new Group {
                        Name = "PS-12-2"
                    },
                    new Group {
                        Name = "PS-12-1"
                    },
                    new Group {
                        Name = "PE-13-1"
                    },
                    new Group {
                        Name = "PE-13-2"
                    },
                    new Group {
                        Name = "PP-13-1"
                    },
                    new Group {
                        Name = "PP-13-2"
                    }
                };
                await Groups.AddRangeAsync(groups);
                await SaveChangesAsync();

                var faculties = new[]
                {
                    new Faculty {
                        Name = "Applied math"
                    },
                    new Faculty {
                        Name = "Philosophy"
                    },
                    new Faculty {
                        Name = "Ecology"
                    }
                };
                await Faculties.AddRangeAsync(faculties);
                await SaveChangesAsync();

                await FacultyGroups.AddRangeAsync(new[] {
                    new FacultyGroup {
                        GroupId = groups[0].Id, FacultyId = faculties[0].Id
                    },
                    new FacultyGroup {
                        GroupId = groups[1].Id, FacultyId = faculties[0].Id
                    },
                    new FacultyGroup {
                        GroupId = groups[2].Id, FacultyId = faculties[2].Id
                    },
                    new FacultyGroup {
                        GroupId = groups[3].Id, FacultyId = faculties[2].Id
                    },
                    new FacultyGroup {
                        GroupId = groups[4].Id, FacultyId = faculties[1].Id
                    },
                    new FacultyGroup {
                        GroupId = groups[5].Id, FacultyId = faculties[1].Id
                    }
                });
                await SaveChangesAsync();

                await GroupStudents.AddRangeAsync(new[] {
                    new GroupStudent {
                        GroupId = groups[0].Id, StudentId = students[0].Id
                    },
                    new GroupStudent {
                        GroupId = groups[1].Id, StudentId = students[1].Id
                    },
                    new GroupStudent {
                        GroupId = groups[2].Id, StudentId = students[2].Id
                    },
                    new GroupStudent {
                        GroupId = groups[3].Id, StudentId = students[3].Id
                    },
                    new GroupStudent {
                        GroupId = groups[4].Id, StudentId = students[4].Id
                    },
                    new GroupStudent {
                        GroupId = groups[5].Id, StudentId = students[5].Id
                    }
                });

                await transaction.CommitAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }