public IViewComponentResult Invoke(int itemid, string name = "", int pagenum = 1, ItemType idtype = ItemType.Blog, bool hottest = false) { ViewData["idtype"] = idtype; ViewData["itemid"] = itemid; ViewData["hottest"] = hottest; var posts = _db.Posts.Include("replies").Where(p => p.ItemId == itemid && p.IdType == idtype); if (!string.IsNullOrEmpty(name)) { posts = posts.Where(p => p.Author == name); ViewBag.relplyusername = name; } X.PagedList.IPagedList <Post> model; if (idtype == ItemType.Blog) { var query = posts.GroupJoin(_db.BlogRatings, p => p.PostId, r => r.PostId, (p, r) => new { post = p, ratings = r }) .SelectMany(a => a.ratings.DefaultIfEmpty(), (p, r) => new { post = p.post, blograting = r }); if (hottest) { query = query.OrderByDescending(p => p.post.Rating).ThenByDescending(p => p.post.PostDate); } else { query = query.OrderByDescending(p => p.post.PostDate); } var paged = query.ToPagedList(pagenum, ReplyPageSize); model = new X.PagedList.StaticPagedList <Post>(paged.Select(a => a.post), paged.GetMetaData()); IDictionary <int, BlogRating> ratings = query.Where(q => q.blograting != null).ToDictionary(q => q.post.PostId, q => q.blograting); ViewBag.ratings = ratings; } else { IQueryable <Post> query; if (hottest) { query = posts.OrderByDescending(p => p.Rating).ThenByDescending(p => p.PostDate); } else { query = posts.OrderByDescending(p => p.PostDate); } model = posts.OrderByDescending(p => p.PostDate).ToPagedList(pagenum, ReplyPageSize); } ViewBag.nicknames = _blogUtil.GetNickNames(model.Select(p => p.Author).Concat(model.SelectMany(p => p.Replies).Select(r => r.Author))); return(View(model)); }
// GET: Compensaciones/Contribuyentes public async Task <ActionResult> Index(int?page) { int paginaNum = 0; paginaNum = page ?? 1; int totalContribuyentes = await ctx.Contar(); int contribuyentesPorPagina = 100; int contribuyenteInicio = paginaNum * contribuyentesPorPagina; int contribuyenteFinal = contribuyenteInicio - contribuyentesPorPagina; var contribuyentes = await ctx.GetAll().OrderBy(e => e.id).Skip(contribuyenteFinal).Take(contribuyentesPorPagina).ToListAsync(); var usersAsIPagedList = new X.PagedList.StaticPagedList <tblPuucContribuyente>(contribuyentes, paginaNum, contribuyentesPorPagina, totalContribuyentes); ViewBag.OnePageOfUsers = usersAsIPagedList; return(View()); }
public async System.Threading.Tasks.Task <JsonResult> Blog([FromHybrid] SearchModel model, int limit = 10, int skip = 0) { limit = System.Math.Min(System.Math.Max(limit, 1), 100); int page = skip <= 0 ? 1 : (skip / limit + 1); if (IsHarmony) { model.Harmony = true; } var blogs = await searchProvider_.SearchBlogAsync(model, page, limit); var items = new X.PagedList.StaticPagedList <BlogPreview>(blogs.Blogs.Select(b => new BlogPreview { Brief = blogUtil_.GetFirstLine(b, true).ToString(), Id = b.BlogID, ThumbUrl = BlogHelper.firstImgPath(b, true), ImageUrl = BlogHelper.firstImgPath(b), Title = b.BlogTitle, CreateDate = b.BlogDate, Url = Url.Action("Details", "Blog", new { id = b.BlogID }, Request.Scheme), }), blogs.Blogs.GetMetaData()); return(Json(new Paged <BlogPreview>(items))); }
private Paged <BlogDetails> ToPaged(X.PagedList.IPagedList <BlogDetailDisplay> blogs) { var names = blogs.Select(b => b.blog.Author).Distinct(); var authors = udb_.Users.Where(u => names.Contains(u.UserName)).ToDictionary(u => u.UserName); var authorInfos = names.Select(n => { if (authors.TryGetValue(n, out UserProfile u)) { var user = Models.App.User.FromUserProfile(u, Url.Action("Show", "Avatar", new { name = u.UserName }, Request.Scheme)); return(user); } return(new User { UserName = n, NickName = n }); }).ToDictionary(u => u.UserName); ratingUtil_.PrepareRatings(blogs.Select(b => b.blog.BlogID)); var ids = blogs.Select(b => b.blog.BlogID); var posts = db_.Posts.Where(p => p.IdType == ItemType.Blog && ids.Contains(p.ItemId)) .GroupJoin(db_.BlogRatings, p => p.PostId, r => r.PostId, (p, r) => new { post = p, ratings = r }) .SelectMany(a => a.ratings.DefaultIfEmpty(), (p, r) => new { p.post, blograting = r, uc = p.post.Ratings.Count(ra => ra.Value == 1), dc = p.post.Ratings.Count(ra => ra.Value == -1), uv = User.Identity.IsAuthenticated ? p.post.Ratings.FirstOrDefault(ra => ra.Rater == User.Identity.Name) : null }) .GroupBy(p => p.post.ItemId, (key, ps) => new { Key = key, Posts = ps .OrderByDescending(p => p.post.Rating) .ThenByDescending(p => p.post.PostDate) .Take(5) }) .ToDictionary(p => p.Key, p => p.Posts); var userRatings = ratingUtil_.GetUsersRatingValues(ids); var items = new X.PagedList.StaticPagedList <BlogDetails>(blogs.Select(bd => { blogUtil_.ProcessBlogDetails(bd); return(GetBlogDetails(bd, authorInfos[bd.blog.Author], posts.ContainsKey(bd.blog.BlogID) ? posts[bd.blog.BlogID].Select(c => new Comment { Author = c.post.Author, CommentId = c.post.PostId, Content = c.post.Content, ItemId = c.post.ItemId, UpvoteCount = c.uc, DownvoteCount = c.dc, IsUpvoted = c.uv == null ? new bool?() : c.uv.Value == 1, IsDownvoted = c.uv == null ? new bool?() : c.uv.Value == -1, CreateDate = c.post.PostDate, Type = Comment.CommentType.Blog, Rating = c.blograting == null ? new int?() : c.blograting.value, }).ToArray() : new Comment[0], userRatings.ContainsKey(bd.blog.BlogID) ? userRatings[bd.blog.BlogID] : new int?())); }), blogs.GetMetaData()); return(new Paged <BlogDetails>(items)); }