public ActionResult SaveNewTheme(CreateThemeViewModel vm) { if (!ModelState.IsValid) { return(SiteErrorHandler.GetBadRequestActionResult(ModelState)); } // Check if the theme name is already in use. if (_themeRepository.IsThemeNameAlreadyInUse(vm.ThemeId, vm.Name)) { return(SiteErrorHandler.GetBadRequestActionResult($"The theme name {vm.Name} is already in use.", nameof(vm.Name))); } var theme = _mapper.Map <ThemeModel>(vm); int id = _themeRepository.CreateTheme(theme, vm.SelectedThemeId); return(Json(new { message = "<strong>Success</strong>: The theme has been created.", themeId = id })); }