Exemple #1
0
        public static async Task Initialize(IServiceProvider serviceProvider, string testUserPw)
        {
            using (var context = new CHSYesWebAppContext(
                       serviceProvider.GetRequiredService <DbContextOptions <CHSYesWebAppContext> >()))
            {
                // For sample purposes seed both with the same password.
                // Password is set with the following:
                // dotnet user-secrets set SeedUserPW <pw>
                // The admin user can do anything
                try
                {
                    var adminID = await EnsureUser(serviceProvider, testUserPw, "*****@*****.**");

                    var roleid = await EnsureRole(serviceProvider, adminID, Constants.ServiceFormAdministratorsRole);

                    // allowed user can create and edit ServiceForms that they create
                    var managerID = await EnsureUser(serviceProvider, testUserPw, "*****@*****.**");
                    await EnsureRole(serviceProvider, managerID, Constants.ServiceFormManagersRole);

                    SeedDB(context, adminID);
                }
                catch (Exception ex)
                {
                    String s;
                    s = ex.Message;
                }
            }
        }
Exemple #2
0
        public static void SeedDB(CHSYesWebAppContext context, string adminID)
        {
            if (context.ServiceForm.Any())
            {
                return;   // DB has been seeded
            }

            context.ServiceForm.AddRange(
                #region snippet_ServiceForm
                new ServiceForm
            {
                ServiceDate               = Convert.ToDateTime("1/1/2018"),
                HourOfService             = 5,
                ServiceDescription        = "Robotics club ",
                RewardedForService        = false,
                StudentSignature          = "Thorsten",
                OrganizationName          = "FLL",
                OrganizationPhone         = "281-888-8888",
                OrganizationWebSite       = "www.fll.com",
                OrganizationStreetAddress = "*****@*****.**",
                SponsorName               = "Mr. Mike",
                SponsorEmail              = "*****@*****.**",
                ParentSignature           = "Thorsten",
                Status  = ContactStatus.Submitted,
                OwnerID = adminID
            },
                #endregion
                #endregion
                new ServiceForm
            {
                ServiceDate               = Convert.ToDateTime("1/1/2018"),
                HourOfService             = 5,
                ServiceDescription        = "Robotics club ",
                RewardedForService        = false,
                StudentSignature          = "Thorsten",
                OrganizationName          = "FLL",
                OrganizationPhone         = "281-888-8888",
                OrganizationWebSite       = "www.fll.com",
                OrganizationStreetAddress = "*****@*****.**",
                SponsorName               = "Mr. Mike",
                SponsorEmail              = "*****@*****.**",
                ParentSignature           = "Thorsten",
                Status  = ContactStatus.Rejected,
                OwnerID = adminID
            },
                new ServiceForm
            {
                ServiceDate               = Convert.ToDateTime("1/1/2018"),
                HourOfService             = 5,
                ServiceDescription        = "Robotics club ",
                RewardedForService        = false,
                StudentSignature          = "Thorsten",
                OrganizationName          = "FLL",
                OrganizationPhone         = "281-888-8888",
                OrganizationWebSite       = "www.fll.com",
                OrganizationStreetAddress = "*****@*****.**",
                SponsorName               = "Mr. Mike",
                SponsorEmail              = "*****@*****.**",
                ParentSignature           = "Thorsten",
                Status  = ContactStatus.Submitted,
                OwnerID = adminID
            }
                );
            context.SaveChanges();
        }