public async Task <IList <ThemeListItem> > GetInstalledThemes() { IList <ThemeListItem> themes = new List <ThemeListItem>(); var themeRootFolder = new DirectoryInfo(Path.Combine(GlobalConfiguration.ContentRootPath, "Themes")); var themeFolders = themeRootFolder.GetDirectories(); foreach (var themeFolder in themeFolders) { var themeJsonPath = Path.Combine(themeFolder.FullName, "theme.json"); if (!File.Exists(themeJsonPath)) { throw new ApplicationException($"Cannot found theme.json for theme {themeFolder.Name}"); } var manifestStr = await File.ReadAllTextAsync(themeJsonPath); ThemeManifest themeManifest; themeManifest = JsonConvert.DeserializeObject <ThemeManifest>(manifestStr); var theme = new ThemeListItem { Name = themeManifest.Name, DisplayName = themeManifest.DisplayName, IsCurrent = themeManifest.Name == _currentThemeName, ThumbnailUrl = $"/themes/{themeManifest.Name}/{themeManifest.Name}.png" }; themes.Add(theme); } return(themes); }
public IActionResult Post([FromBody] ThemeListItem model) { if (ModelState.IsValid) { _themeService.SetCurrentTheme(model.Name); return(Ok()); } return(new BadRequestObjectResult(ModelState)); }
public async Task <IActionResult> Post([FromBody] ThemeListItem model) { if (ModelState.IsValid) { await _themeService.SetCurrentTheme(model.Name); return(Accepted()); } return(BadRequest(ModelState)); }