Example #1
0
        /// <summary>
        /// Creates a new store object
        /// </summary>
        /// <param name="storeName">Name of the new store</param>
        /// <param name="adminEmail">Email address of initial super user account</param>
        /// <param name="adminPassword">Password for initial super user account</param>
        /// <param name="switchContext">If true, the token context is switched to the new store.  If false, the token
        /// context remains the same as it was before the method is called.</param>
        /// <returns>The created store object</returns>
        public static Store CreateStore(string storeName, string adminEmail, string adminPassword, bool switchContext)
        {
            //NEED TO SAVE THE CURRENT STORE CONTEXT
            Store masterStore = Token.Instance.Store;
            //CREATE THE STORE
            Store newStore = new Store();

            newStore.Name             = storeName;
            newStore.NextOrderId      = 1;
            newStore.OrderIdIncrement = 1;
            newStore.WeightUnit       = CommerceBuilder.Shipping.WeightUnit.Pounds;
            newStore.MeasurementUnit  = CommerceBuilder.Shipping.MeasurementUnit.Inches;
            newStore.Save();
            //NEED TO SWITCH OUR TOKEN CONTEXT TO THE NEW STORE
            Token.Instance.InitStoreContext(newStore);
            //INITIALIZE THE AUDIT LOGS
            Logger.Audit(AuditEventType.ApplicationStarted, true, string.Empty);
            //INITIALIZE ROLES AND GROUPS
            RoleDataSource.EnsureDefaultRoles();
            GroupDataSource.EnsureDefaultGroups();
            //CREATE THE SUPER USER
            User user = UserDataSource.CreateUser(adminEmail, adminPassword);

            //ASSIGN USER TO APPROPRIATE GROUP
            CommerceBuilder.Users.Group suGroup = GroupDataSource.LoadForName("Super Users");
            user.UserGroups.Add(new UserGroup(user.UserId, suGroup.GroupId));
            user.Save();
            //RESET THE ORIGINAL STORE CONTEXT
            if (!switchContext)
            {
                Token.Instance.InitStoreContext(masterStore);
            }
            //RETURN THE NEW STORE
            return(newStore);
        }