Ejemplo n.º 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 }));
        }