Skip to content

Commit fe654ae

Browse files
committed
Minor theme selection fix
1 parent d37dc7e commit fe654ae

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/App/Pages/Admin/Settings/Themes.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
@if (Model.ShowMessage)
4949
{
5050
<script>toastr.success('@Model.Message')</script>
51-
Model.Message = "";
51+
}
52+
@if (Model.ShowError)
53+
{
54+
<script>toastr.error('@Model.Error')</script>
5255
}
5356
}

src/App/Pages/Admin/Settings/Themes.cshtml.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Core.Data;
33
using Core.Services;
44
using Microsoft.AspNetCore.Mvc;
5+
using System;
56
using System.Collections.Generic;
67
using System.IO;
78
using System.Linq;
@@ -35,17 +36,43 @@ public async Task<IActionResult> OnGetAsync(string id, string act)
3536
if (!IsAdmin)
3637
return RedirectToPage("../Shared/_Error", new { code = 403 });
3738

38-
if(act == "set" && !string.IsNullOrEmpty(id))
39+
if (act == "set" && !string.IsNullOrEmpty(id))
3940
{
4041
var theme = _db.CustomFields.Single(f => f.AuthorId == 0 && f.Name == Constants.BlogTheme);
41-
theme.Content = id;
42+
43+
if(theme == null)
44+
{
45+
theme = new CustomField { AuthorId = 0, Name = Constants.BlogTheme, Content = id };
46+
_db.CustomFields.Add(theme);
47+
}
48+
else
49+
{
50+
theme.Content = id;
51+
Message = Resources.Updated;
52+
}
4253
_db.Complete();
43-
Message = Resources.Updated;
4454
}
4555

4656
if(act == "del" && !string.IsNullOrEmpty(id))
4757
{
48-
Message = Resources.Removed;
58+
var slash = Path.DirectorySeparatorChar.ToString();
59+
var themeContent = $"{AppSettings.WebRootPath}{slash}themes{slash}{id.ToLower()}";
60+
var themeViews = $"{AppSettings.ContentRootPath}{slash}Views{slash}Themes{slash}{id}";
61+
62+
try
63+
{
64+
if (Directory.Exists(themeContent))
65+
Directory.Delete(themeContent, true);
66+
67+
if (Directory.Exists(themeViews))
68+
Directory.Delete(themeViews, true);
69+
70+
Message = Resources.Removed;
71+
}
72+
catch (Exception ex)
73+
{
74+
Error = ex.Message;
75+
}
4976
}
5077

5178
BlogItem = await _db.CustomFields.GetBlogSettings();

0 commit comments

Comments
 (0)