Example #1
0
        public ActionResult Configure(string theme, int storeId, IDictionary <string, object> values, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageThemes))
            {
                return(AccessDeniedView());
            }

            if (!_themeRegistry.ThemeManifestExists(theme))
            {
                return(RedirectToAction("List", new { storeId = storeId }));
            }

            // get current for later restore on parse error
            var currentVars = _themeVarService.GetThemeVariables(theme, storeId);

            // save now
            values = FixThemeVarValues(values);
            _themeVarService.SaveThemeVariables(theme, storeId, values);

            // check for parsing error
            var    manifest = _themeRegistry.GetThemeManifest(theme);
            string error    = ValidateLess(manifest, storeId);

            if (error.HasValue())
            {
                // restore previous vars
                try
                {
                    _themeVarService.DeleteThemeVariables(theme, storeId);
                }
                finally
                {
                    // we do it here to absolutely ensure that this gets called
                    _themeVarService.SaveThemeVariables(theme, storeId, currentVars);
                }

                TempData["LessParsingError"]    = error.Trim().TrimStart('\r', '\n', '/', '*').TrimEnd('*', '/', '\r', '\n');
                TempData["OverriddenThemeVars"] = values;
                NotifyError(T("Admin.Configuration.Themes.Notifications.ConfigureError"));
                return(RedirectToAction("Configure", new { theme = theme, storeId = storeId }));
            }

            // activity log
            _services.CustomerActivity.InsertActivity("EditThemeVars", T("ActivityLog.EditThemeVars"), theme);

            NotifySuccess(T("Admin.Configuration.Themes.Notifications.ConfigureSuccess"));

            return(continueEditing ?
                   RedirectToAction("Configure", new { theme = theme, storeId = storeId }) :
                   RedirectToAction("List", new { storeId = storeId }));
        }
Example #2
0
        public ActionResult Configure(string theme, int storeId, IDictionary <string, object> values, bool continueEditing)
        {
            if (!_themeRegistry.ThemeManifestExists(theme))
            {
                return(RedirectToAction("List", new { storeId }));
            }

            try
            {
                values = FixThemeVarValues(values);
                _themeVarService.SaveThemeVariables(theme, storeId, values);

                Services.CustomerActivity.InsertActivity("EditThemeVars", T("ActivityLog.EditThemeVars"), theme);

                NotifySuccess(T("Admin.Configuration.Themes.Notifications.ConfigureSuccess"));

                return(continueEditing
                    ? RedirectToAction("Configure", new { theme, storeId })
                    : RedirectToAction("List", new { storeId }));
            }
            catch (ThemeValidationException ex)
            {
                TempData["SassParsingError"]    = ex.Message.Trim().TrimStart('\r', '\n', '/', '*').TrimEnd('*', '/', '\r', '\n');
                TempData["OverriddenThemeVars"] = ex.AttemptedVars;
                NotifyError(T("Admin.Configuration.Themes.Notifications.ConfigureError"));
            }
            catch (Exception ex)
            {
                NotifyError(ex);
            }

            // Fail.
            return(RedirectToAction("Configure", new { theme, storeId }));
        }