Пример #1
0
        public ActionResult SaveThemeVariables(ThemeEditVariablesViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(SiteErrorHandler.GetBadRequestActionResult(ModelState));
            }

            // Check if the theme exists.
            if (!_themeRepository.DoesThemeExist(vm.ThemeId))
            {
                return(SiteErrorHandler.GetBadRequestActionResult("Could not find the theme.", ""));
            }

            // Map the variables to a readable model.
            var themeVariables = _mapper.Map <List <ThemeVariableValueModel> >(vm.Variables);
            IEnumerable <int> themeVariableValueIds = themeVariables.Select(x => x.ThemeVariableValueId);

            // Check if the theme variable values exist.
            if (!_themeRepository.DoThemeVariableValuesExist(themeVariableValueIds))
            {
                return(SiteErrorHandler.GetBadRequestActionResult("Could not find the theme variable.", ""));
            }

            // Update the theme variable values.
            _themeRepository.UpdateThemeVariableValues(themeVariables);

            return(Json(new { message = "<strong>Success</strong>: The theme variables have been updated.", themeId = vm.ThemeId }));
        }
Пример #2
0
        // Edit theme variables.
        public ActionResult EditThemeVariables(int id)
        {
            // Get the theme variables.
            var themeVariables = _themeRepository.GetThemeVariableValues(id);

            // Get the variable categories.
            var themeVariableCategories = _themeRepository.GetThemeVariableCategories();

            // Map them into view models.
            var variablesVm  = _mapper.Map <List <ThemeVariableValueViewModel> >(themeVariables);
            var categoriesVm = _mapper.Map <List <ThemeVariableCategoryViewModel> >(themeVariableCategories);

            // Put the two view models in a wrapper view model and return the view.
            var vm = new ThemeEditVariablesViewModel
            {
                ThemeId            = id,
                VariableCategories = categoriesVm,
                Variables          = variablesVm
            };

            return(View(vm));
        }