22using Core . Data ;
33using Core . Services ;
44using Microsoft . AspNetCore . Mvc ;
5+ using Newtonsoft . Json ;
56using System ;
67using System . Collections . Generic ;
78using System . IO ;
@@ -15,9 +16,11 @@ public class ThemesModel : AdminPageModel
1516 IDataService _db ;
1617 IStorageService _storage ;
1718 INotificationService _ns ;
19+ string slash = Path . DirectorySeparatorChar . ToString ( ) ;
1820
1921 public IEnumerable < ThemeItem > Themes { get ; set ; }
2022 public BlogItem BlogItem { get ; set ; }
23+ public WidgetsModel Widgets { get ; set ; }
2124
2225 public ThemesModel ( IDataService db , IStorageService storage , INotificationService ns )
2326 {
@@ -28,30 +31,22 @@ public ThemesModel(IDataService db, IStorageService storage, INotificationServic
2831
2932 public async Task < IActionResult > OnGetAsync ( )
3033 {
31- var author = await _db . Authors . GetItem ( a => a . AppUserName == User . Identity . Name ) ;
32- IsAdmin = author . IsAdmin ;
33-
34- Notifications = await _ns . GetNotifications ( author . Id ) ;
34+ await SetModel ( ) ;
3535
3636 if ( ! IsAdmin )
3737 return RedirectToPage ( "../Shared/_Error" , new { code = 403 } ) ;
3838
39- BlogItem = await _db . CustomFields . GetBlogSettings ( ) ;
40- Themes = GetThemes ( ) ;
41-
4239 return Page ( ) ;
4340 }
4441
4542 public async Task < IActionResult > OnPostAsync ( )
4643 {
4744 string act = Request . Form [ "hdnAct" ] ;
4845 string id = Request . Form [ "hdnTheme" ] ;
49-
46+
5047 var author = await _db . Authors . GetItem ( a => a . AppUserName == User . Identity . Name ) ;
5148 IsAdmin = author . IsAdmin ;
5249
53- Notifications = await _ns . GetNotifications ( author . Id ) ;
54-
5550 if ( ! IsAdmin )
5651 return RedirectToPage ( "../Shared/_Error" , new { code = 403 } ) ;
5752
@@ -74,7 +69,7 @@ public async Task<IActionResult> OnPostAsync()
7469
7570 if ( act == "del" && ! string . IsNullOrEmpty ( id ) )
7671 {
77- var slash = Path . DirectorySeparatorChar . ToString ( ) ;
72+
7873 var themeContent = $ "{ AppSettings . WebRootPath } { slash } themes{ slash } { id . ToLower ( ) } ";
7974 var themeViews = $ "{ AppSettings . ContentRootPath } { slash } Views{ slash } Themes{ slash } { id } ";
8075
@@ -94,10 +89,30 @@ public async Task<IActionResult> OnPostAsync()
9489 }
9590 }
9691
92+ await SetModel ( ) ;
93+
94+ return Page ( ) ;
95+ }
96+
97+ async Task SetModel ( )
98+ {
99+ var author = await _db . Authors . GetItem ( a => a . AppUserName == User . Identity . Name ) ;
100+ IsAdmin = author . IsAdmin ;
101+
102+ Notifications = await _ns . GetNotifications ( author . Id ) ;
103+
97104 BlogItem = await _db . CustomFields . GetBlogSettings ( ) ;
98105 Themes = GetThemes ( ) ;
99106
100- return Page ( ) ;
107+ string jsonFile = $ "{ AppSettings . ContentRootPath } { slash } Views{ slash } Themes{ slash } { BlogItem . Theme } { slash } { BlogItem . Theme } .json";
108+ if ( System . IO . File . Exists ( jsonFile ) )
109+ {
110+ using ( StreamReader r = new StreamReader ( jsonFile ) )
111+ {
112+ string json = r . ReadToEnd ( ) ;
113+ Widgets = JsonConvert . DeserializeObject < WidgetsModel > ( json ) ;
114+ }
115+ }
101116 }
102117
103118 List < ThemeItem > GetThemes ( )
0 commit comments