Blog presentation

This commit is contained in:
Paul Schneider
2024-12-03 01:44:58 +00:00
parent a4932d08f1
commit f91f000405
7 changed files with 58 additions and 52 deletions

View File

@ -16,6 +16,7 @@ using Microsoft.Extensions.Options;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;
using Yavsc.ViewModels.Blog;
using System.Collections;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
@ -45,7 +46,7 @@ namespace Yavsc.Controllers
public async Task<IActionResult> Index(string id)
{
if (!string.IsNullOrEmpty(id)) {
return await UserPosts(id);
return View("UserPosts", await UserPosts(id));
}
return View();
}
@ -63,13 +64,10 @@ namespace Yavsc.Controllers
).ToList());
}
[Route("~/Blog/{userName}/{pageLen?}/{pageNum?}")]
[AllowAnonymous]
public async Task<IActionResult> UserPosts(string userName, int pageLen=10, int pageNum=0)
private async Task<IEnumerable<BlogPost>> UserPosts(string userName, int pageLen=10, int pageNum=0)
{
string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == userName))?.Id ?? null ;
var result = _context.UserPosts(posterId, User.Identity.Name);
return View("Index", result.ToArray().Skip(pageLen*pageNum).Take(pageLen).OrderByDescending(p => p.DateCreated).ToList().GroupBy(p=> p.Title ));
return _context.UserPosts(posterId, User.Identity.Name);
}
// GET: Blog/Details/5
[AllowAnonymous]