Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions source/DasBlog.Web.UI/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class AdminController : DasBlogBaseController
private readonly IBlogManager blogManager;
private readonly IHostApplicationLifetime appLifetime;
private readonly ILogger<AdminController> logger;
private readonly List<PostViewModel> posts = [];

public AdminController(IDasBlogSettings dasBlogSettings, IFileSystemBinaryManager fileSystemBinaryManager, IMapper mapper,
IBlogManager blogManager, IHostApplicationLifetime appLifetime, ILogger<AdminController> logger) : base(dasBlogSettings)
Expand All @@ -36,6 +37,8 @@ public AdminController(IDasBlogSettings dasBlogSettings, IFileSystemBinaryManage
this.blogManager = blogManager;
this.appLifetime = appLifetime;
this.logger = logger;
this.posts = blogManager.GetAllEntries()
.Select(entry => mapper.Map<PostViewModel>(entry)).ToList();
}

[HttpGet]
Expand All @@ -46,8 +49,7 @@ public IActionResult Settings()
var dbsvm = new DasBlogSettingsViewModel();
dbsvm.MetaConfig = mapper.Map<MetaViewModel>(dasBlogSettings.MetaTags);
dbsvm.SiteConfig = mapper.Map<SiteViewModel>(dasBlogSettings.SiteConfiguration);
dbsvm.Posts = blogManager.GetAllEntries()
.Select(entry => mapper.Map<PostViewModel>(entry)).ToList();
dbsvm.Posts = posts;

return View(dbsvm);
}
Expand All @@ -60,7 +62,8 @@ public IActionResult Settings(DasBlogSettingsViewModel settings)
//save settings and reload...
if (ModelState.ErrorCount > 0)
{
return Settings(settings);
settings.Posts = posts;
return View("Settings", settings);
}

var site = mapper.Map<SiteConfig>(settings.SiteConfig);
Expand All @@ -74,15 +77,17 @@ public IActionResult Settings(DasBlogSettingsViewModel settings)
{
ModelState.AddModelError("", "Unable to save Site configuration file.");
logger.LogError(new EventDataItem(EventCodes.Error, null, "Unable to save Site Config file"));
return Settings(settings);
settings.Posts = posts;
return View("Settings", settings);
}
dasBlogSettings.SiteConfiguration = site;

if (!fileSystemBinaryManager.SaveMetaConfig(meta))
{
ModelState.AddModelError("", "Unable to save Meta configuration file.");
logger.LogError(new EventDataItem(EventCodes.Error, null, "Unable to save Site Config file"));
return Settings(settings);
settings.Posts = posts;
return View("Settings", settings);
}
dasBlogSettings.MetaTags = meta;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

namespace DasBlog.Web.Models.AdminViewModels
{
public class BlogPostListViewModel
{
public string Name { get; set; }
public class BlogPostListViewModel
{
public string Name { get; set; }

public string Id { get; set; }
public string Id { get; set; }

public List<BlogPostListViewModel> Init(List<PostViewModel> posts)
{
var allposts = posts.Select(p => new BlogPostListViewModel { Name = p.Title, Id = p.EntryId }).ToList();
public List<BlogPostListViewModel> Init(List<PostViewModel> posts)
{
var allposts = posts.Select(p => new BlogPostListViewModel { Name = p.Title, Id = p.EntryId }).ToList();

allposts.Insert(0, new BlogPostListViewModel { Name = "--Disable Pinning--", Id = "" });
allposts.Insert(0, new BlogPostListViewModel { Name = "--Disable Pinning--", Id = "" });

return allposts;
}
}
return allposts;
}
}
}