Beispiel #1
0
        public JsonpResult GetPostsBy(string by, string id, int?page)
        {
            var pageIndex = page ?? 0;
            IEnumerable <Post> source;

            if (by == "category")
            {
                source = BlogServices.FindPagedPostsByCategory(false, id, pageIndex, 10).Where(p => p.IsPublic && p.IsAboutMe == false);
            }
            else
            {
                source = BlogServices.FindPagedPostsByTag(false, id, pageIndex, 10).Where(p => p.IsPublic && p.IsAboutMe == false);
            }
            var data = new
            {
                posts =
                    from p in source
                    select new
                {
                    postid        = p.PostId,
                    title         = p.Title,
                    description   = p.Description,
                    commentscount = p.Comments.Count <Comment>(),
                    date          = p.DateCreated.ToShortDateString(),
                    category      = p.Category.Name,
                    thumbnailpath = getImageUrl(p.Image),
                    user          = p.User.Username
                },
                pendingposts = source.Count() == 10 ? true : false
            };

            return(this.Jsonp(data));
        }
Beispiel #2
0
        public ActionResult GetPostsByTag(string id, int?page)
        {
            ViewBag.Action = "GetPostsByTag";
            ViewBag.Route  = "Default";
            ViewBag.Tag    = id;
            ViewBag.Title  = "Posts - " + id;
            var pageIndex = page ?? 0;

            if ((CodeFirstSecurity.IsAuthenticated) && (CodeFirstRoleServices.IsUserInRole(CodeFirstSecurity.CurrentUserName, BgResources.Security_PremiumRole)))
            {
                return(View("Posts", BlogServices.FindPagedPostsByTag(true, id, pageIndex, Int32.Parse(BgResources.Pager_PostPerPage))));
            }
            else
            {
                return(View("Posts", BlogServices.FindPagedPostsByTag(true, id, pageIndex, Int32.Parse(BgResources.Pager_PostPerPage))));
            }
        }