refactoring

This commit is contained in:
2018-11-28 13:53:26 +00:00
parent 0d5fbf264f
commit b8f79d4e80
3 changed files with 5 additions and 4 deletions

View File

@ -13,6 +13,7 @@ using Yavsc.ViewModels.Auth;
using Microsoft.AspNet.Mvc.Rendering;
using Yavsc.Models.Blog;
using Yavsc.Helpers;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace Yavsc.Controllers
@ -78,13 +79,13 @@ namespace Yavsc.Controllers
).ToList());
}
[Route("/Blog/{id?}")]
[Route("/Blog/{userName}/{pageLen?}/{pageNum?}")]
[AllowAnonymous]
public async Task<IActionResult> UserPosts(string id)
public async Task<IActionResult> UserPosts(string userName, int pageLen=10, int pageNum=0)
{
string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == id))?.Id ?? null ;
string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == userName))?.Id ?? null ;
var result = _context.UserPosts(posterId, User.Identity.Name);
return View("Index", result.OrderByDescending(p => p.DateCreated).ToList().GroupBy(p=> p.Title ));
return View("Index", result.OrderByDescending(p => p.DateCreated).ToList().Skip(pageLen*pageNum).Take(pageLen).GroupBy(p=> p.Title ));
}
// GET: Blog/Details/5
[AllowAnonymous]