public async Task <IActionResult> Features(int page = 0, string userName = "******") { ViewData["Title"] = "Features"; var posts = context.Posts.OrderByDescending(x => x.Date).ToList(); var user = await _userManager.FindByEmailAsync(userName); posts = posts.Where(x => context.Favors.Any(y => y.IsPost && y.PostId == x.Id && y.UserId == user.Id)).ToList(); if (posts != null && posts.Count > 10) { ViewData["Pages"] = posts.Count % 10 == 0 ? posts.Count / 10 : posts.Count / 10 + 1; if (posts.Count - page * 10 > 9) { posts = posts.GetRange(page * 10, 10); } else { posts = posts.GetRange(page * 10, posts.Count - page * 10); } } var model = new ViewModels.PostIndex { Posts = posts, UserId = "0", GroupId = 0, Page = page }; return(View(model)); }
public IActionResult Index(int page = 0, string userId = "0", int groupId = 0) { ViewData["Title"] = "Posts"; var posts = context.Posts.OrderByDescending(x => x.Date).ToList(); if (userId != "0") { posts = posts.Where(x => x.UserId == userId).ToList(); } else if (groupId != 0) { posts = posts.Where(x => x.GroupId == groupId).ToList(); } if (posts != null && posts.Count > 10) { ViewData["Pages"] = posts.Count % 10 == 0 ? posts.Count / 10 : posts.Count / 10 + 1; if (posts.Count - page * 10 > 9) { posts = posts.GetRange(page * 10, 10); } else { posts = posts.GetRange(page * 10, posts.Count - page * 10); } } var model = new ViewModels.PostIndex { Posts = posts, UserId = userId, GroupId = groupId, Page = page }; return(View(model)); }