예제 #1
0
 public static Identity.AspNetIdentityUser AspNetIdentityUser(this UserProfile userProfile)
 {
     if (userProfile == null)
     {
         return null;
     }
     Identity.AspNetIdentityContext identityCtx = new Identity.AspNetIdentityContext();
     return identityCtx.AspNetIdentityUser(userProfile);
 }
예제 #2
0
 public static List<Identity.AspNetIdentityRole> AspNetIdentityRoles(this UserProfile userProfile)
 {
     if (userProfile == null)
     {
         return new List<Identity.AspNetIdentityRole>();
     }
     Identity.AspNetIdentityContext identityCtx = new Identity.AspNetIdentityContext();
     return identityCtx.AspNetIdentityRoles(userProfile);
 }
예제 #3
0
 public Identity.AspNetIdentityUser AspNetIdentityUser(GStoreData.Models.UserProfile userProfile)
 {
     if (userProfile == null)
     {
         throw new ApplicationException("User profile is null, cannot check identity user with null profile");
     }
     Identity.AspNetIdentityContext ctx  = new Identity.AspNetIdentityContext();
     Identity.AspNetIdentityUser    user = ctx.Users.SingleOrDefault(usr => usr.Id == userProfile.UserId);
     if (user == null)
     {
         throw new ApplicationException("AspNetUser not found. Check for extra profiles in UserProfile table with duplicate email address."
                                        + "\n\tUserId (from profile): " + userProfile.UserId
                                        + "\n\tEmail (from profile): " + userProfile.Email
                                        + "\n\tUserProfileId (from profile): " + userProfile.UserProfileId);
     }
     return(user);
 }
예제 #4
0
 public static ICollection<Identity.AspNetIdentityUserRole> AspNetIdentityUserRoles(this UserProfile userProfile)
 {
     Identity.AspNetIdentityContext identityCtx = new Identity.AspNetIdentityContext();
     return identityCtx.AspNetIdentityUserRoles(userProfile);
 }
예제 #5
0
        public static void AddSeedData(this IGstoreDb storeDb, bool force = false)
        {
            if (Settings.AppDoNotSeedDatabase && !force)
            {
                return;
            }

            string adminUserName = "******";
            string adminEmail = "*****@*****.**";
            string adminPhone = "888-555-1212";
            string adminPassword = "******";
            string adminFullName = "System Admin";
            string adminAddressLine1 = "1234 West Hollywood Blvd";
            string adminAddressLine2 = "Suite 104";
            string adminCity = "Venice Beach";
            string adminState = "CA";
            string adminPostalCode = "99999";
            CountryCodeEnum adminCountryCode = CountryCodeEnum.US;

            string browserUserName = "******";
            string browserEmail = "*****@*****.**";
            string browserPhone = "888-555-1212";
            string browserPassword = "******";
            string browserFullName = "John Doe User";
            string browserAddressLine1 = "1234 Main St";
            string browserAddressLine2 = null;
            string browserCity = "Los Angeles";
            string browserState = "CA";
            string browserPostalCode = "99999";
            CountryCodeEnum browserCountryCode = CountryCodeEnum.US;

            string preferedThemeName = Settings.AppDefaultThemeFolderName;
            bool loadSampleProducts = Settings.AppSeedSampleProducts;

            if (HttpContext.Current != null)
            {
                EventLogExtensions.CreateEventLogFolders(HttpContext.Current);
            }

            Identity.AspNetIdentityContext ctx = new Identity.AspNetIdentityContext();
            ctx.Database.Initialize(true);
            ctx.CreateRoleIfNotExists("AccountAdmin");
            ctx.CreateRoleIfNotExists("NotificationAdmin");
            ctx.CreateRoleIfNotExists("StoreAdmin");
            ctx.CreateRoleIfNotExists("ClientAdmin");
            ctx.CreateRoleIfNotExists("SystemAdmin");
            Identity.AspNetIdentityUser adminAspNetUser = ctx.CreateSystemAdminUserIfNotExists(adminUserName, adminEmail, adminPhone, adminPassword);
            Identity.AspNetIdentityUser browserUser = ctx.CreateUserIfNotExists(browserUserName, browserEmail, browserPhone, browserPassword);
            ctx.Dispose();

            UserProfile adminProfile = storeDb.GetUserProfileByEmail(adminUserName, false);
            //Create admin user profile if it does not exist
            if (adminProfile == null)
            {
                adminProfile = storeDb.CreateSeedAdminProfile(adminAspNetUser.Id, adminUserName, adminEmail, adminFullName, adminAddressLine1, adminAddressLine2, adminCity, adminState, adminPostalCode, adminCountryCode);
            }
            storeDb.UserName = adminProfile.UserName;
            storeDb.CachedUserProfile = adminProfile;

            if (storeDb.Clients.IsEmpty())
            {
                Client newClient = storeDb.CreateSeedClient("New Company", "NewClient");
            }
            Client firstClient = storeDb.Clients.All().First();

            if (storeDb.Themes.IsEmpty())
            {
                storeDb.CreateSeedThemes(firstClient);
            }
            if (storeDb.Themes.IsEmpty())
            {
                throw new ApplicationException("No themes found. Add themes to ~/Content/Server/Themes/(ThemeName) folders");
            }
            Theme selectedTheme = storeDb.Themes.Where(t => t.Name == preferedThemeName.ToLower()).FirstOrDefault();
            if (selectedTheme == null)
            {
                //select random theme
                int themeCount = storeDb.Themes.All().Count();
                Random rndNumber = new Random();
                int randomThemeIndex = rndNumber.Next(1, themeCount);
                selectedTheme = storeDb.Themes.All().OrderBy(t => t.Order).Skip(randomThemeIndex - 1).First();
            }

            if (storeDb.PageTemplates.IsEmpty())
            {
                storeDb.CreateSeedPageTemplates(firstClient);
            }

            if (storeDb.StoreFronts.IsEmpty())
            {
                StoreFront newStoreFront = storeDb.CreateSeedStoreFront(firstClient, adminProfile);
            }
            StoreFront firstStoreFront = storeDb.StoreFronts.All().First();
            storeDb.CachedStoreFront = firstStoreFront;

            //config
            StoreFrontConfiguration firstStoreFrontConfig = firstStoreFront.CurrentConfigOrAny();
            if (firstStoreFrontConfig == null)
            {
                string storeFrontName = "New Storefront";
                string storeFrontFolder = "NewStoreFront";
                firstStoreFrontConfig = storeDb.CreateSeedStoreFrontConfig(firstStoreFront, storeFrontName, storeFrontFolder, adminProfile, selectedTheme);
            }

            firstClient = firstStoreFront.Client;

            if (storeDb.StoreBindings.IsEmpty())
            {
                StoreBinding storeBinding = storeDb.CreateSeedStoreBindingToCurrentUrl(firstStoreFrontConfig);
            }

            if (storeDb.Pages.IsEmpty())
            {
                storeDb.CreateSeedPagesHelper(firstStoreFrontConfig);
            }

            if (storeDb.WebForms.IsEmpty())
            {
                //this is only called if there are pages, but no webforms (rare edge case)
                storeDb.CreateSeedWebForms(firstClient);
            }

            if (loadSampleProducts && storeDb.ProductCategories.IsEmpty())
            {
                CreateSeedProducts(storeDb, firstStoreFrontConfig);
            }

            //add sample discount codes
            if (storeDb.Discounts.IsEmpty())
            {
                storeDb.CreateSeedDiscounts(firstStoreFront);
            }

            //add browser user
            UserProfile browserProfile = browserUser.GetUserProfile(storeDb, false);
            if (browserProfile == null)
            {
                browserProfile = storeDb.CreateSeedUserProfile(firstStoreFront, browserUser.Id, browserUserName, browserEmail, browserFullName, browserAddressLine1, browserAddressLine2, browserCity, browserState, browserPostalCode, browserCountryCode);
            }
        }