1- using Core . Services ;
1+ using Core . Data ;
2+ using Core . Services ;
23using Microsoft . AspNetCore . Mvc ;
34using System ;
5+ using System . Collections . Generic ;
46using System . Linq ;
57
68namespace Common . Widgets
@@ -20,14 +22,17 @@ public IViewComponentResult Invoke(string theme, string widget)
2022 var keyAuth = $ "{ theme } -{ widget } -auth";
2123 var keyCat = $ "{ theme } -{ widget } -cat";
2224 var keyMax = $ "{ theme } -{ widget } -max";
25+ var keyTmpl = $ "{ theme } -{ widget } -tmpl";
2326
2427 var selectedAuth = _db . CustomFields . GetCustomValue ( keyAuth ) ;
2528 var selectedCat = _db . CustomFields . GetCustomValue ( keyCat ) ;
2629 var maxRecords = _db . CustomFields . GetCustomValue ( keyMax ) ;
30+ var template = _db . CustomFields . GetCustomValue ( keyTmpl ) ;
2731
2832 if ( selectedAuth == "All" ) { selectedAuth = "" ; }
2933 if ( selectedCat == "All" ) { selectedCat = "" ; }
3034 if ( string . IsNullOrEmpty ( maxRecords ) ) { maxRecords = "10" ; }
35+ if ( string . IsNullOrEmpty ( template ) ) { template = "<a href=\" /posts/{0}\" class=\" list-group-item list-group-item-action\" >{1}</a>" ; }
3136
3237 var posts = _db . BlogPosts . All ( )
3338 . Where ( p => p . Published > DateTime . MinValue )
@@ -55,7 +60,7 @@ public IViewComponentResult Invoke(string theme, string widget)
5560 if ( ! int . TryParse ( maxRecords , out maxRec ) )
5661 maxRec = 10 ;
5762
58- var model = posts . Take ( maxRec ) . ToList ( ) ;
63+ var model = new PostListWidgetModel { Title = widget , Posts = posts . Take ( maxRec ) . ToList ( ) , Template = template } ;
5964
6065 return View ( "~/Views/Widgets/PostList/Index.cshtml" , model ) ;
6166 }
@@ -73,17 +78,26 @@ public PostListController(IDataService db)
7378
7479 [ HttpPost ]
7580 [ Route ( "edit" ) ]
76- public IActionResult Edit ( string selAuthors , string selCats , string txtMaxRecords , string hdnWidget , string hdnTheme )
81+ public IActionResult Edit ( string selAuthors , string selCats , string txtMaxRecords , string txtTemplate , string hdnWidget , string hdnTheme )
7782 {
7883 var keyAuth = $ "{ hdnTheme } -{ hdnWidget } -auth";
7984 var keyCat = $ "{ hdnTheme } -{ hdnWidget } -cat";
8085 var keyMax = $ "{ hdnTheme } -{ hdnWidget } -max";
86+ var keyTmpl = $ "{ hdnTheme } -{ hdnWidget } -tmpl";
8187
8288 _db . CustomFields . SaveCustomValue ( keyAuth , selAuthors ) ;
8389 _db . CustomFields . SaveCustomValue ( keyCat , selCats ) ;
8490 _db . CustomFields . SaveCustomValue ( keyMax , txtMaxRecords ) ;
91+ _db . CustomFields . SaveCustomValue ( keyTmpl , txtTemplate ) ;
8592
8693 return Redirect ( "~/admin/settings/themes" ) ;
8794 }
8895 }
96+
97+ public class PostListWidgetModel
98+ {
99+ public string Title { get ; set ; }
100+ public string Template { get ; set ; }
101+ public List < BlogPost > Posts { get ; set ; }
102+ }
89103}
0 commit comments