public bool AddNewAdminEmail(string adminEmail)
        {
            if (GetApprovedAdminEmail(adminEmail) != null)
            {
                return(false);
            }
            var adminEmailModel = new RegisteredAdminEmail()
            {
                RegisteredAdminEmailAddress = adminEmail,
                EmailHasBeenRegistered      = false
            };

            _context.RegisteredAdminEmailValues.Add(adminEmailModel);
            return(true);
        }
コード例 #2
0
        public static void Initialize(ApplicationDbContext context)
        {
            context.Database.EnsureCreated();

            // Look for any users.
            if (context.UserValues.Any())
            {
                return;   // DB has been seeded
            }

            var users = new User[] {
                new Student {
                    UserAccountType       = UserAccountType.Student,
                    UserBestContactNumber = "09047152678",
                    UserDob                           = new DateTime(1999, 5, 26),
                    UserEmail                         = "*****@*****.**",
                    UserFaculty                       = "Software Engineering",
                    UserGenderType                    = UserGenderType.Female,
                    UserHasLoggedIn                   = false,
                    UserHomePhone                     = "+810127189874",
                    UserMobile                        = "09047152678",
                    UserPass                          = "******",
                    UserPrefFirstName                 = "Kirino",
                    UserLastName                      = "Kousaka",
                    UserName                          = "******",
                    StudentCountry                    = "Japan",
                    StudentCourseType                 = "CO9067",
                    StudentDegreeType                 = StudentDegreeType.Undergraduate,
                    StudentDegreeYearType             = StudentDegreeYearType.ThirdYear,
                    StudentLanguage                   = "Japanese",
                    StudentPermissionToUseData        = true,
                    StudentStatusType                 = StudentStatusType.International,
                    StudentOtherEducationalBackground = "None"
                },
                new Admin {
                    UserAccountType       = UserAccountType.Admin,
                    UserBestContactNumber = "09037981124",
                    UserDob           = new DateTime(1998, 8, 14),
                    UserEmail         = "*****@*****.**",
                    UserFaculty       = "Software Engineering",
                    UserGenderType    = UserGenderType.Female,
                    UserHasLoggedIn   = false,
                    UserHomePhone     = "+810128670798",
                    UserMobile        = "09037981124",
                    UserPass          = "******",
                    UserPrefFirstName = "Sora",
                    UserLastName      = "Kasugano",
                    UserName          = "******",
                }
            };

            foreach (User user in users)
            {
                context.UserValues.Add(user);
            }

            context.SaveChanges();

            var registeredEmails = new RegisteredAdminEmail[] {
                new RegisteredAdminEmail {
                    RegisteredAdminEmailAddress = "*****@*****.**",
                    EmailHasBeenRegistered      = true
                },
                new RegisteredAdminEmail {
                    RegisteredAdminEmailAddress = "*****@*****.**",
                    EmailHasBeenRegistered      = false
                }
            };

            foreach (var registeredEmail in registeredEmails)
            {
                context.RegisteredAdminEmailValues.Add(registeredEmail);
            }

            var userAccountStatuses = new UserAccountStatus[] {
                new UserAccountStatus {
                    UserAccountConfirmed  = true,
                    UserConfirmationToken = Guid.NewGuid(),
                    UserId = GetUserIdFromEmail("*****@*****.**", users)
                },
                new UserAccountStatus {
                    UserAccountConfirmed  = true,
                    UserConfirmationToken = Guid.NewGuid(),
                    UserId = GetUserIdFromEmail("*****@*****.**", users)
                }
            };

            foreach (var accountStatus in userAccountStatuses)
            {
                context.UserAccountStatusValues.Add(accountStatus);
            }

            context.SaveChanges();
        }