|
2 | 2 | using Core.Data; |
3 | 3 | using Core.Services; |
4 | 4 | using Microsoft.AspNetCore.Mvc; |
| 5 | +using System; |
5 | 6 | using System.Collections.Generic; |
6 | 7 | using System.IO; |
7 | 8 | using System.Linq; |
@@ -35,17 +36,43 @@ public async Task<IActionResult> OnGetAsync(string id, string act) |
35 | 36 | if (!IsAdmin) |
36 | 37 | return RedirectToPage("../Shared/_Error", new { code = 403 }); |
37 | 38 |
|
38 | | - if(act == "set" && !string.IsNullOrEmpty(id)) |
| 39 | + if (act == "set" && !string.IsNullOrEmpty(id)) |
39 | 40 | { |
40 | 41 | 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 | + } |
42 | 53 | _db.Complete(); |
43 | | - Message = Resources.Updated; |
44 | 54 | } |
45 | 55 |
|
46 | 56 | if(act == "del" && !string.IsNullOrEmpty(id)) |
47 | 57 | { |
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 | + } |
49 | 76 | } |
50 | 77 |
|
51 | 78 | BlogItem = await _db.CustomFields.GetBlogSettings(); |
|
0 commit comments