@@ -13,22 +13,17 @@ public HtmlBlock(IDataService db)
1313 _db = db ;
1414 }
1515
16- public IViewComponentResult Invoke ( string id , string theme , string author )
16+ public IViewComponentResult Invoke ( string theme , string widget )
1717 {
18- string model = @"<ul class=""blog-social nav ml-auto my-auto"">
19- <li class=""blog-social-item""><a href=""#"" target=""_blank"" class=""blog-social-link""><i class=""blog-social-icon fa fa-twitter""></i></a></li>
20- <li class=""blog-social-item""><a href=""#"" target=""_blank"" class=""blog-social-link""><i class=""blog-social-icon fa fa-google-plus""></i></a></li>
21- <li class=""blog-social-item""><a href=""#"" target=""_blank"" class=""blog-social-link""><i class=""blog-social-icon fa fa-facebook-official""></i></a></li>
22- </ul>" ;
23-
24- var existing = _db . HtmlWidgets . Single ( w => w . Name == id && w . Theme == theme && w . Author == author ) ;
18+ string model = "" ;
19+ var existing = _db . HtmlWidgets . Single ( w => w . Name == widget && w . Theme == theme && w . Author == "0" ) ;
2520
2621 if ( existing == null )
2722 {
2823 _db . HtmlWidgets . Add ( new Core . Data . HtmlWidget {
29- Name = id ,
24+ Name = widget ,
3025 Theme = theme ,
31- Author = author ,
26+ Author = "0" ,
3227 Content = model
3328 } ) ;
3429 _db . Complete ( ) ;
@@ -41,4 +36,39 @@ public IViewComponentResult Invoke(string id, string theme, string author)
4136 return View ( "~/Views/Widgets/HtmlBlock/Index.cshtml" , model ) ;
4237 }
4338 }
39+
40+ [ Route ( "widgets/api/htmlblock" ) ]
41+ public class HtmlBlockController : Controller
42+ {
43+ IDataService _db ;
44+
45+ public HtmlBlockController ( IDataService db )
46+ {
47+ _db = db ;
48+ }
49+
50+ [ HttpPost ]
51+ [ Route ( "edit" ) ]
52+ public IActionResult Edit ( string txtWidget , string txtTheme , string txtHtml )
53+ {
54+ var existing = _db . HtmlWidgets . Single ( w => w . Name == txtWidget && w . Theme == txtTheme && w . Author == "0" ) ;
55+
56+ if ( existing == null )
57+ {
58+ _db . HtmlWidgets . Add ( new Core . Data . HtmlWidget
59+ {
60+ Name = txtWidget ,
61+ Theme = txtTheme ,
62+ Author = "0" ,
63+ Content = txtHtml
64+ } ) ;
65+ }
66+ else
67+ {
68+ existing . Content = txtHtml ;
69+ }
70+ _db . Complete ( ) ;
71+ return Redirect ( "~/admin/settings/themes" ) ;
72+ }
73+ }
4474}
0 commit comments