Example #1
0
        /// <summary>
        /// index the user id.
        /// </summary>
        /// <param name="userId">the user id.</param>
        /// <returns>the action result.</returns>

        public async Task <ActionResult> Index(ulong userId)
        {
            IEnumerable <PostItemModel> postList;

            var roleId = (ulong)HttpContext.Session.GetInt32("RoleId");

            var canDeletePost = false;

            if (roleId == (ulong)RoleEnum.Writer)
            {
                postList = await _postService.GetPostsDrafOrRejectedsByAutorId(autorId : userId)
                           .ConfigureAwait(false);
            }
            else
            {
                postList = await _postService.GetPostsToApprove()
                           .ConfigureAwait(false);

                canDeletePost = true;
            }



            var postListModel = new PostListModel
            {
                AutorId       = userId,
                Items         = postList,
                CanDeletePost = canDeletePost
            };

            return(View(postListModel));
        }
Example #2
0
        public ActionResult List()
        {
            var    model      = new PostListModel();
            string keyword    = StringHelper.SqlEncode(PressRequest.GetQueryString("keyword"));
            int    categoryId = PressRequest.GetQueryInt("categoryid", -1);
            int    userId     = PressRequest.GetQueryInt("userid", -1);
            int    hide       = PressRequest.GetQueryInt("hide", -1);

            var catelist = _categoryService.GetCategoryList();

            const int pageSize  = 10;
            int       count     = 0;
            int       pageIndex = PressRequest.GetInt("page", 1);
            int       cateid    = PressRequest.GetQueryInt("cateid", -1);
            int       tagid     = PressRequest.GetQueryInt("tagid", -1);

            catelist.Add(new CategoryInfo()
            {
                CateName = "全部", CategoryId = -1
            });
            model.CateSelectItem = catelist.ConvertAll(c => new SelectListItem {
                Text = c.CateName, Value = c.CategoryId.ToString(), Selected = c.CategoryId == cateid
            });

            if (cateid > 0)
            {
                pageIndex = pageIndex + 1;
            }
            var postlist = _postService.GetPostPageList(pageSize, pageIndex, out count, categoryId.ToString(), tagid, -1, -1, -1, -1, -1, "", "", keyword);

            model.PageList.LoadPagedList(postlist);
            model.PostList = (List <PostInfo>)postlist;
            return(View(model));
        }
Example #3
0
        public ActionResult ListPostCategory(string catURL)
        {
            string        layout = "Layout/";
            PostListModel model;

            try
            {
                model = this.CacheGetOrSet($"{catURL}-p1", CacheRegion.Category, () =>
                {
                    var postCat      = new PostListModel();
                    int hotNum       = 0;
                    postCat.category = _cs.GetCategory(url: catURL, haveParner: true).Convert(withSEO: true);
                    var hotPosts     = _ps.GetListPost(hotNum, categoryID: postCat.category.ID, isHot: true);
                    var Posts        = _ps.GetListPost(CATEGORY_LIST_POST_NUM_IN_PAGE, categoryID: postCat.category.ID, hotPostNum: hotNum);

                    postCat.HostPosts = hotPosts.Convert(withUser: true);
                    var t             = postCat.HostPosts;

                    //postCat.Posts = Posts.Convert(withUser: true);
                    postCat.Posts = Posts.Convert();

                    var y = postCat.Posts;
                    return(postCat);
                });
            }
            catch (Exception ex)
            {
                return(HttpNotFound());
            }
            // Lấy ra những bài Post khi bấm vào mục Category

            return(View("Layout/Default", model));
        }
Example #4
0
        public static PostListModel ToListViewModel(this PostInfo postInfo)
        {
            var model = new PostListModel();

            model.Id             = postInfo.Id;
            model.Subject        = postInfo.Subject;
            model.SectionId      = postInfo.SectionId;
            model.AuthorId       = postInfo.AuthorId;
            model.AuthorName     = string.IsNullOrEmpty(postInfo.AuthorName) ? postInfo.AuthorId : postInfo.AuthorName;
            model.CreatedOn      = postInfo.CreatedOn.ToString("MM-dd HH:mm");
            model.ReplyCount     = postInfo.ReplyCount;
            model.LastUpdateTime = postInfo.LastUpdateTime.ToString("MM-dd HH:mm");
            if (!string.IsNullOrEmpty(postInfo.MostRecentReplyId))
            {
                model.MostRecentReply = new ReplyModel
                {
                    Id         = postInfo.MostRecentReplyId,
                    AuthorId   = postInfo.MostRecentReplierId,
                    AuthorName = string.IsNullOrEmpty(postInfo.MostRecentReplierName) ? postInfo.MostRecentReplierId : postInfo.MostRecentReplierName,
                    CreatedOn  = postInfo.LastUpdateTime.ToString("MM-dd HH:mm")
                };
            }

            return(model);
        }
        public ActionResult Index()
        {
            PostListModel model = new PostListModel();
            //int hotPostNum = 14;
            //int ListPostNum = 11;
            var hotPostNum  = Request.Browser.IsMobileDevice ? MOBILE_HOME_HOT_POST_NUM_IN_PAGE : HOME_HOT_POST_NUM_IN_PAGE;
            var ListPostNum = Request.Browser.IsMobileDevice ? MOBILE_HOME_LIST_POST_NUM_IN_PAGE : HOME_LIST_POST_NUM_IN_PAGE;

            var hotPosts = _PostServices.GetListPost(hotPostNum, isHot: true);
            var posts    = _PostServices.GetListPost(ListPostNum, hotPostNum: hotPostNum);

            model.HotPosts = hotPosts.Convert(withUser: true);
            model.Posts    = posts.Convert(withUser: true);

            if (model == null)
            {
                model = new PostListModel();
            }

            return(View(model));

            //var hot = model.HotPosts.ToList();
            //var post = model.Posts.ToList();


            //var total = hot.Concat(post);
            //var result = total.OrderByDescending(x => x.CreateDate).ToPagedList(page ?? 1, 25);
            //return View(result);
        }
        public ActionResult GetPostList(PostListModel model)
        {
            var db = new ZkDataContext();

            model = model ?? new PostListModel();

            var thread = db.ForumThreads.First(x => x.ForumThreadID == model.ThreadID && (x.RestrictedClanID == null || x.RestrictedClanID == Global.ClanID));

            var posts = thread.ForumPosts.AsQueryable();

            if (!string.IsNullOrEmpty(model.Search))
            {
                posts = Global.ForumPostIndexer.FilterPosts(posts, model.Search);
            }
            if (!string.IsNullOrEmpty(model.User))
            {
                var filterAccountID = (db.Accounts.FirstOrDefault(x => x.Name == model.User) ?? db.Accounts.FirstOrDefault(x => x.Name.Contains(model.User)))?.AccountID;
                if (filterAccountID.HasValue)
                {
                    posts = posts.Where(x => x.AuthorAccountID == filterAccountID);
                }
            }

            model.Data   = posts.OrderBy(x => x.ForumPostID);
            model.Thread = thread;

            if (!model.DisablePostComment)
            {
                var mode = thread.ForumCategory.ForumMode;
                model.DisablePostComment = thread.IsLocked || mode == ForumMode.Maps || mode == ForumMode.Missions || mode == ForumMode.SpringBattles || mode == ForumMode.Clans || mode == ForumMode.Planets || mode == ForumMode.GameModes;
            }

            return(View("PostList", model));
        }
Example #7
0
        public IActionResult Index(string name)
        {
            // get all the posts in this category
            if (!string.IsNullOrEmpty(name))
            {
                ViewData["Title"] = "Posts in " + name;
                ViewBag.Category  = name;

                var titlesInCategory = new Dictionary <string, string>();
                var postsForView     = new List <Metadata>();
                var postsInCategory  = _indexer.Metadata.Where(x => x.Categories.Contains(name));
                foreach (var post in postsInCategory)
                {
                    postsForView.Add(post);
                    titlesInCategory.Add(post.Slug, post.Title);
                }

                ViewBag.TitlesInCategory = titlesInCategory;
                var model = new PostListModel
                {
                    Posts = postsForView.ToArray()
                            // TODO - add paging
                };
                return(View("PostList", model));
            }

            return(RedirectToRoute("blog-index"));
        }
        public ActionResult GetPostList(PostListModel model)
        {
            var db = new ZkDataContext();

            model = model ?? new PostListModel();

            var thread = db.ForumThreads.First(x => x.ForumThreadID == model.ThreadID && (x.RestrictedClanID == null || x.RestrictedClanID == Global.ClanID));

            var posts = thread.ForumPosts.AsQueryable();

            if (!string.IsNullOrEmpty(model.Search))
            {
                posts = Global.ForumPostIndexer.FilterPosts(posts, model.Search);
            }
            if (!string.IsNullOrEmpty(model.User))
            {
                var filterAccountID = (db.Accounts.FirstOrDefault(x => x.Name == model.User) ?? db.Accounts.FirstOrDefault(x => x.Name.Contains(model.User)))?.AccountID;
                if (filterAccountID.HasValue)
                {
                    posts = posts.Where(x => x.AuthorAccountID == filterAccountID);
                }
            }

            model.Posts  = posts.OrderBy(x => x.ForumPostID);
            model.Thread = thread;

            return(View("PostList", model));
        }
Example #9
0
        public ActionResult Index()
        {
            IDatabaseUtility connection = new MySQLUtility();

            try
            {
                connection.Connect();
                CategoryListModel categorylist = new CategoryListModel(connection);

                List <Category> categories = categorylist.GetAll();

                List <List <Post> > categoryposts = new List <List <Post> >();

                foreach (Category category in categories)
                {
                    PostListModel postlist = new PostListModel(connection);
                    List <Post>   posts    = postlist.GetByCategoryLimit(category.link, 0, 5, "created_time DESC");
                    categoryposts.Add(posts);
                }

                ViewBag.categories = categories;
                return(View(categoryposts));
            }
            catch (DBException e)
            {
                ViewBag.ErrorMessage = e.Message;
                return(View("_errors"));
            }
        }
Example #10
0
        public async Task <PostListModel> GetList(Guid archiveId)
        {
            var model = new PostListModel
            {
                PostTypes = App.PostTypes.Select(t => new PostListModel.PostTypeItem
                {
                    Id     = t.Id,
                    Title  = t.Title,
                    AddUrl = "manager/post/add/"
                }).ToList()
            };

            // Get posts
            model.Posts = (await _api.Posts.GetAllAsync <PostInfo>(archiveId))
                          .Select(p => new PostListModel.PostItem
            {
                Id        = p.Id.ToString(),
                Title     = p.Title,
                TypeName  = model.PostTypes.First(t => t.Id == p.TypeId).Title,
                Category  = p.Category.Title,
                Published = p.Published.HasValue ? p.Published.Value.ToString("yyyy-MM-dd HH:mm") : null,
                Status    = GetState(p, false),
                EditUrl   = "manager/post/"
            }).ToList();

            // Get categories
            model.Categories = (await _api.Posts.GetAllCategoriesAsync(archiveId))
                               .Select(c => new PostListModel.CategoryItem
            {
                Id    = c.Id.ToString(),
                Title = c.Title
            }).ToList();

            return(model);
        }
Example #11
0
        public ActionResult Category(string pagename)
        {
            var          model = new PostListModel();
            CategoryInfo cate  = _categoryService.GetCategory(pagename);

            model.Category = cate;
            if (cate != null)
            {
                int categoryId = cate.CategoryId;
                model.MetaKeywords    = cate.CateName;
                model.MetaDescription = cate.Description;
                ViewBag.Title         = cate.CateName;
                model.Url             = ConfigHelper.SiteUrl + "category/" + Jqpress.Framework.Utils.StringHelper.SqlEncode(pagename) + "/page/{0}";

                const int pageSize  = 10;
                int       count     = 0;
                int       pageIndex = PressRequest.GetInt("page", 1);
                int       cateid    = PressRequest.GetQueryInt("cateid", -1);
                int       tagid     = PressRequest.GetQueryInt("tagid", -1);
                if (cateid > 0)
                {
                    pageIndex = pageIndex + 1;
                }
                var cateids  = categoryId + "," + _categoryService.GetCategoryList().FindAll(c => c.ParentId == categoryId).Aggregate(string.Empty, (current, t) => current + (t.CategoryId + ",")).TrimEnd(',');
                var postlist = _postService.GetPostPageList(pageSize, pageIndex, out count, cateids.TrimEnd(','), tagid, -1, -1, -1, -1, -1, "", "", "");
                model.PageList.LoadPagedList(postlist);
                model.PostList = (List <PostInfo>)postlist;
            }
            model.IsDefault = 0;


            return(View(model.Category.ViewName, model));
        }
Example #12
0
        public async Task <PostListModel> FetchAll(int page)
        {
            var countTask = postRepo.Query()
                            .CountAsync();

            var postsTask = postRepo.Query()
                            .OrderByDescending(p => p.CreatedAt)
                            .Skip((page - 1) * PostListPageSize)
                            .Take(10)
                            .Select(p => new Post
            {
                Id               = p.Id,
                Title            = p.Title,
                Subtitle         = p.Subtitle,
                ThumbnailImageId = p.ThumbnailImageId,
                Author           = p.Author,
                UpdatedAt        = p.UpdatedAt,
                CreatedAt        = p.CreatedAt,
                Published        = p.Published
            })
                            .ToListAsync();

            var model = new PostListModel();

            await Task.WhenAll(countTask, postsTask);

            var count = await countTask;
            var posts = await postsTask;

            model.Page  = page;
            model.Pages = (int)Math.Ceiling(count / (double)PostListPageSize);
            model.Posts = posts.Select(PostModel.FromPost);

            return(model);
        }
Example #13
0
        /// <summary>
        /// 归档
        /// </summary>
        public void Archive()
        {
            var      model = new PostListModel();
            string   year  = Jqpress.Framework.Web.PressRequest.GetQueryString("year");
            string   month = Jqpress.Framework.Web.PressRequest.GetQueryString("month");
            DateTime date  = Convert.ToDateTime(year + "-" + month);

            begindate = date.ToString();
            enddate   = date.AddMonths(1).ToString();

            model.MetaKeywords    = "归档";
            model.MetaDescription = BlogConfig.GetSetting().SiteName + date.ToString("yyyy-MM") + "的归档";
            model.PageTitle       = "归档:" + date.ToString("yyyy-MM");
            model.PostMessage     = string.Format("<h2 class=\"post-message\">归档:{0}</h2>", date.ToString("yyyy-MM"));
            model.Url             = ConfigHelper.SiteUrl + "archive/" + date.ToString("yyyyMM") + "/page/{0}" + BlogConfig.GetSetting().RewriteExtension;
            int recordCount = 0;

            model.PostList = PostService.GetPostList(BlogConfig.GetSetting().PageSizePostCount, pageindex,
                                                     out recordCount, categoryId, tagId, userId, -1, 1, -1, 0,
                                                     begindate, enddate, keyword);
            model.Pager = Pager.CreateHtml(BlogConfig.GetSetting().PageSizePostCount, recordCount, model.Url);

            model.IsDefault = 0;
            model.ThemeName = _themeName;
            th.Put("Model", model);

            Display(th, _listTemplate);
        }
Example #14
0
        /// <summary>
        /// 作者
        /// </summary>
        public void Author()
        {
            var model = new PostListModel();

            string   userName = Jqpress.Framework.Web.PressRequest.GetQueryString("username");
            UserInfo user     = UserService.GetUser(userName);

            if (user != null)
            {
                userId                = user.UserId;
                model.MetaKeywords    = user.NickName;
                model.MetaDescription = user.Description;
                model.PageTitle       = user.NickName;

                model.PostMessage = string.Format("<h2 class=\"post-message\">作者:{0}</h2>", user.NickName);
                model.Url         = ConfigHelper.SiteUrl + "author/" + HttpContext.Current.Server.UrlEncode(userName) + "/page/{0}" + BlogConfig.GetSetting().RewriteExtension;
                int recordCount = 0;
                model.PostList = PostService.GetPostList(BlogConfig.GetSetting().PageSizePostCount, pageindex,
                                                         out recordCount, categoryId, tagId, userId, -1, 1, -1, 0,
                                                         begindate, enddate, keyword);
                model.Pager = Pager.CreateHtml(BlogConfig.GetSetting().PageSizePostCount, recordCount, model.Url);
            }

            model.IsDefault = 0;
            model.ThemeName = _themeName;
            th.Put("Model", model);

            Display(th, _listTemplate);
        }
Example #15
0
        /// <summary>
        /// 标签
        /// </summary>
        public void Tag()
        {
            var model = new PostListModel();

            TagInfo tag = TagService.GetTagBySlug(slug);

            if (tag != null)
            {
                tagId = tag.TagId;
                model.MetaKeywords    = tag.CateName;
                model.MetaDescription = tag.Description;
                model.PageTitle       = tag.CateName;
                model.PostMessage     = string.Format("<h2 class=\"post-message\">标签:{0}</h2>", tag.CateName);
                model.Url             = ConfigHelper.SiteUrl + "tag/" + HttpContext.Current.Server.UrlEncode(slug) + "/page/{0}" + BlogConfig.GetSetting().RewriteExtension;
                int recordCount = 0;
                model.PostList = PostService.GetPostList(BlogConfig.GetSetting().PageSizePostCount, pageindex,
                                                         out recordCount, categoryId, tagId, userId, -1, 1, -1, 0,
                                                         begindate, enddate, keyword);
                model.Pager = Pager.CreateHtml(BlogConfig.GetSetting().PageSizePostCount, recordCount, model.Url);
            }
            model.IsDefault = 0;
            model.ThemeName = _themeName;
            th.Put("Model", model);

            Display(th, _listTemplate);
        }
Example #16
0
 private void PageBackButton_Click(object sender, RoutedEventArgs e)
 {
     if (PostListModel.PresentPage - 1 > 0)
     {
         PostListModel.PresentPage -= 1;
         PostListModel.SetSource(GetPostList(url, PostListModel.PresentPage));
     }
 }
Example #17
0
 private void PageNextButton_Click(object sender, RoutedEventArgs e)
 {
     if (PostListModel.PresentPage + 1 <= PostListModel.MaxPage)
     {
         PostListModel.PresentPage += 1;
         PostListModel.SetSource(GetPostList(url, PostListModel.PresentPage));
     }
 }
 public MainPage()
 {
     InitializeComponent();
     NewImage          = new NewImageHelper();
     PostListSingleton = PostListModel.Instance(PostList, EmptyMessage);
     SettingsSlide.InitialiseSettingsElements();
     SettingsSlide.TranslationX -= Measurements.VirtualScreenWidth;
 }
        public IActionResult PostList()
        {
            var model = new PostListModel()
            {
                Post = unitOfWork.postRepository.GetAll().ToList()
            };

            return(View(model));
        }
Example #20
0
        public ActionResult <PostListModel> GetPostsInCategory([FromRoute] string name)
        {
            var posts = _postService.GetPostsInCategory(name);
            var model = new PostListModel
            {
                Posts = posts
            };

            return(new JsonResult(model));
        }
        public IActionResult CategorySubjectList()
        {
            var model = new PostListModel()
            {
                Post     = unitOfWork.postRepository.GetAll().ToList(),
                Category = unitOfWork.categoryRepository.GetAll().ToList(),
                Subject  = unitOfWork.subjectRepository.GetAll().ToList()
            };

            return(View(model));
        }
Example #22
0
 public static Post MapListModelToEntity(PostListModel postDetailModel)
 {
     return(new Post
     {
         Id = postDetailModel.Id,
         Title = postDetailModel.Title,
         Author = UserMapper.MapListModelToEntity(postDetailModel.Author),
         Content = postDetailModel.Content,
         CreationTime = postDetailModel.CreationTime
     });
 }
Example #23
0
        /*******************************************************
        * Helpers
        * *****************************************************/

        private PostListModel CreatePostListModel(Post post)
        {
            var model = new PostListModel
            {
                Score = post.Score,
                Type  = post.PostType
            };

            model.Url = CreateLink(post.ID);
            return(model);
        }
Example #24
0
 public PostPage()
 {
     InitializeComponent();
     winhttp = new WinHttpRequest();
     PostListView.ItemsSource    = PostListViewModel.GetInstance();
     MaxPageText.DataContext     = PageViewModel.GetInstance();
     PresentPageText.DataContext = PageViewModel.GetInstance();
     // 학사 공지사항을 default로 설정 //
     url = "https://www.koreatech.ac.kr/kor/CMS/NoticeMgr/bachelorList.do";
     PostListModel.SetSource(GetPostList(url, 1));
 }
Example #25
0
        /// <summary>
        /// 加载feed
        /// </summary>
        public void Feed()
        {
            int    categoryId = Jqpress.Framework.Web.PressRequest.GetQueryInt("categoryid", -1);
            int    postId     = Jqpress.Framework.Web.PressRequest.GetQueryInt("postid", -1);
            string action     = Jqpress.Framework.Web.PressRequest.GetQueryString("action", true);

            //   HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = "text/xml";
            if (BlogConfig.GetSetting().RssStatus == 1)
            {
                switch (action)
                {
                case "comment":
                    List <CommentInfo> commentList = CommentService.GetCommentList(BlogConfig.GetSetting().RssRowCount, 1, -1, postId, 0, 1, -1, null);
                    PostInfo           commentPost = PostService.GetPost(postId);
                    HttpContext.Current.Response.Write("<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\" xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\">\r\n");
                    HttpContext.Current.Response.Write("    <channel>\r\n");
                    HttpContext.Current.Response.Write("        <title><![CDATA[" + (commentPost == null ? BlogConfig.GetSetting().SiteName : commentPost.Title) + "的评论]]></title>\r\n");
                    HttpContext.Current.Response.Write("        <link>" + (commentPost == null ? ConfigHelper.SiteUrl : commentPost.Url) + "</link>\r\n");
                    HttpContext.Current.Response.Write("        <description><![CDATA[" + BlogConfig.GetSetting().SiteDescription + "]]></description>\r\n");
                    HttpContext.Current.Response.Write("        <pubDate>" + DateTime.Now.ToString("r") + "</pubDate>\r\n");
                    HttpContext.Current.Response.Write("        <generator>jqpress</generator>\r\n");
                    HttpContext.Current.Response.Write("        <language>zh-cn</language>\r\n");
                    foreach (CommentInfo comment in commentList)
                    {
                        HttpContext.Current.Response.Write("        <item>\r\n");
                        HttpContext.Current.Response.Write("            <title><![CDATA[" + comment.Author + "对" + comment.Post.Title + "的评论]]></title>\r\n");
                        HttpContext.Current.Response.Write("            <link>" + comment.Url + "</link>\r\n");
                        HttpContext.Current.Response.Write("            <guid>" + comment.Url + "</guid>\r\n");
                        HttpContext.Current.Response.Write("            <author><![CDATA[" + comment.Author + "]]></author>\r\n");

                        HttpContext.Current.Response.Write(string.Format("          <description><![CDATA[{0}]]></description>\r\n", comment.Contents));
                        HttpContext.Current.Response.Write("            <pubDate>" + comment.CreateTime.ToString("r") + "</pubDate>\r\n");
                        HttpContext.Current.Response.Write("        </item>\r\n");
                    }
                    HttpContext.Current.Response.Write("    </channel>\r\n");
                    HttpContext.Current.Response.Write("</rss>\r\n");
                    break;

                default:
                    var model = new PostListModel();
                    model.PostList = PostService.GetPostList(BlogConfig.GetSetting().RssRowCount, categoryId, -1, -1, 1, -1, 0);
                    th.Put("Model", model);
                    Display(th, "feed.config");
                    break;
                }
            }
            else
            {
                HttpContext.Current.Response.Write("<rss>error</rss>\r\n");
            }
            //  HttpContext.Current.Response.End();
        }
Example #26
0
        public ItemDetailPage()
        {
            InitializeComponent();

            var item = new PostListModel {
                Text        = "Item 1",
                Description = "This is an item description."
            };

            viewModel      = new ItemDetailViewModel(item);
            BindingContext = viewModel;
        }
Example #27
0
        public async Task <PostListModel> GetList(Guid archiveId)
        {
            var page = await _api.Pages.GetByIdAsync <PageInfo>(archiveId);

            var pageType = App.PageTypes.GetById(page.TypeId);

            var model = new PostListModel
            {
                PostTypes = App.PostTypes.Select(t => new PostListModel.PostTypeItem
                {
                    Id     = t.Id,
                    Title  = t.Title,
                    AddUrl = "manager/post/add/"
                }).ToList()
            };

            // We have specified the post types that should be available
            // in this archive. Filter them accordingly
            if (pageType.ArchiveItemTypes.Count > 0)
            {
                model.PostTypes = model.PostTypes
                                  .Where(t => pageType.ArchiveItemTypes.Contains(t.Id))
                                  .ToList();
            }

            // Get drafts
            var drafts = await _api.Posts.GetAllDraftsAsync(archiveId);

            // Get posts
            model.Posts = (await _api.Posts.GetAllAsync <PostInfo>(archiveId))
                          .Select(p => new PostListModel.PostItem
            {
                Id          = p.Id.ToString(),
                Title       = p.Title,
                TypeName    = model.PostTypes.First(t => t.Id == p.TypeId).Title,
                Category    = p.Category.Title,
                Published   = p.Published.HasValue ? p.Published.Value.ToString("yyyy-MM-dd HH:mm") : null,
                Status      = GetState(p, drafts.Contains(p.Id)),
                isScheduled = p.Published.HasValue && p.Published.Value > DateTime.Now,
                EditUrl     = "manager/post/edit/"
            }).ToList();

            // Get categories
            model.Categories = (await _api.Posts.GetAllCategoriesAsync(archiveId))
                               .Select(c => new PostListModel.CategoryItem
            {
                Id    = c.Id.ToString(),
                Title = c.Title
            }).ToList();

            return(model);
        }
Example #28
0
        public async Task <IActionResult> Categories(string name, int page = 1)
        {
            var pager = new Pager(page);
            var posts = await _db.BlogPosts.GetListByCategory(name, pager);

            var model = new PostListModel {
                Posts = posts, Pager = pager
            };

            SetViewBag();
            ViewData["category"] = name;

            return(View($"~/Views/Themes/{AppSettings.Theme}/Category.cshtml", model));
        }
Example #29
0
        private PostListModel GetPostList(int page, string category = null)
        {
            var pageSize  = _options.PageSize;
            var posts     = _postService.GetPosts(page * pageSize, pageSize, category);
            var postCount = _postService.GetNumberOfPosts(category);

            var pagingFunction = (category == null) ? (Func <int, string, string>)GetPagedIndexLink : GetPagedCategoryLink;
            var model          = new PostListModel
            {
                Posts = posts
            };

            return(model);
        }
Example #30
0
        public IActionResult GetAllPosts(Paging pagingInfo)
        {
            var posts = postservice.GetAllPost(pagingInfo).ToList();

            var result = posts.Select(
                x => {
                var postListModel = new PostListModel {
                    Title = x.Title, id = x.Id
                };


                //   postListModel.Url = Url.Link(nameof(GetPostById), new { x.Id });

                return(postListModel);
            });

            //var total = postservice.TotalPosts();
            //var pages = (int)Math.Ceiling(total / (double)pagingInfo.PageSize);

            //var prev = pagingInfo.Page > 0
            //    ? Url.Link(nameof(GetAllPosts),
            //        new { page = pagingInfo.Page - 1, pagingInfo.PageSize })
            //    : null;

            //var next = pagingInfo.Page < pages - 1
            //    ? Url.Link(nameof(GetAllPosts),
            //        new { page = pagingInfo.Page + 1, pagingInfo.PageSize })
            //    : null;

            //var result = new
            //{
            //     pagination = new
            //     {
            //         Prev = prev,
            //         Next = next,
            //         Total = total,
            //         Pages = pages,
            //     },
            //     Data = new
            //     {
            //         Data = posts
            //     }



            //};


            return(Ok(result));
        }
Example #31
0
        public ActionResult Detail(string id, int? page)
        {
            int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

            _themeDoc = _themeService.GetTheme(id);
            if (_themeDoc != null)
            {
                var model = new PostListModel
                                {
                                    Posts =
                                        _postService.GetPosts(_themeDoc.ThemeId, currentPageIndex, DefaultPageSize).
                                        Select(MapPost).ToPagedList(currentPageIndex, DefaultPageSize,
                                                                    _postService.GetPostsCount(_themeDoc.ThemeId)),
                                };

                return View(model);
            }

            return View("Index");
        }
Example #32
0
        public PostListModel get_posts(int reader, bool all = true, int ctype = 0, int PAGE = 0, string TOPIC = "")
        {
            //Get the post based on supplied data (like page, topic, and if everyone/only logged in people can see it)
            int total = -1;
            List<PostModel> fetched_Posts = new List<PostModel>();
            List<int> post_cid_list = new List<int>();

            //The following makes a custom query that changes depending on the data available
            string SQL_Query = "SELECT * FROM content";

            if (reader != 0)
            {
                if (TOPIC != "")
                {
                    SQL_Query += (" NATURAL JOIN contopic WHERE (cid IN (SELECT cid FROM friend NATURAL JOIN visible WHERE reader = " + reader + ") OR cid NOT IN (SELECT cid FROM visible) OR poster = " + reader + ") AND topic = '" + TOPIC + "'");
                }
                else
                {
                    SQL_Query += (" WHERE (cid IN (SELECT cid FROM friend NATURAL JOIN visible WHERE reader = " + reader + ") OR cid NOT IN (SELECT cid FROM visible) OR poster = " + reader + ")");
                }
            }
            else
            {
                SQL_Query += (" WHERE ctype = 0");
            }

            if (all)
                SQL_Query += ";";
            else
                SQL_Query += (" LIMIT 5 OFFSET " + (PAGE * 5) + ";");

            try
            {
                using (MySqlConnection connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnString"].ConnectionString))
                {
                    if (connection.State != System.Data.ConnectionState.Open)
                        connection.Open();

                    MySqlCommand command = new MySqlCommand(SQL_Query, connection);
                    MySqlDataReader dr = command.ExecuteReader();

                    while (dr.Read())
                    {// Get the pid, ctype, ctext, pid and ptime for the fetched posts
                        fetched_Posts.Add(new PostModel
                        {
                            cid = dr.GetInt32("cid"),
                            ctype = dr.GetInt32("ctype"),
                            ctext = dr.GetString("ctext"),
                            pid = dr.GetInt32("poster"),
                            ptime = dr.GetString("ptime"),
                            post_Topics = new List<string>()
                        });
                        post_cid_list.Add(dr.GetInt32("cid"));
                    }
                    dr.Close();

                    foreach (PostModel x in fetched_Posts)
                    {//For the fetched posts, add the authors name into the Model
                        command = new MySqlCommand("SELECT fname FROM person WHERE pid = " + x.pid + ";", connection);
                        dr = command.ExecuteReader();
                        if (dr.Read())
                            x.fname = dr.GetString("fname");
                        dr.Close();
                    }

                    foreach (PostModel x in fetched_Posts)
                    {//For the fetched posts, grab the average rating the post has
                        command = new MySqlCommand("SELECT AVG(rtg) FROM rate WHERE cid = " + x.cid + ";", connection);
                        dr = command.ExecuteReader();
                        if (dr.Read())
                            if (!dr.IsDBNull(0))
                                x.avg_rtg = dr.GetInt32(0);
                            else
                                x.avg_rtg = int.MinValue;
                        dr.Close();
                    }

                    if (TOPIC == "")
                        foreach (PostModel x in fetched_Posts)
                        {//If were not looking for posts with specific topics, fetch the topics of each post (if any)
                            command = new MySqlCommand("SELECT topic FROM contopic WHERE cid = " + x.cid + ";", connection);
                            dr = command.ExecuteReader();
                            if (dr.Read())
                                x.post_Topics.Add(dr.GetString("topic"));
                            dr.Close();
                        }

                    if (TOPIC == "")
                    {
                        command = new MySqlCommand("SELECT COUNT(cid) FROM content WHERE (cid IN (SELECT cid FROM friend NATURAL JOIN visible WHERE reader = " + reader + ") OR cid NOT IN (SELECT cid FROM visible) OR poster = " + reader + ");", connection);
                        total = (Convert.ToInt32(command.ExecuteScalar()));
                        connection.Close(); //Added close because it was always open
                    }
                    else
                    {
                        command = new MySqlCommand("SELECT COUNT(topic) FROM contopic WHERE topic = '" + TOPIC + "';", connection);
                        total = (Convert.ToInt32(command.ExecuteScalar()));
                        connection.Close(); //Added close because it was always open
                    }
                }

            }
            catch (Exception ex)
            {
                //return Content("An error occured: " + ex.Message);
            }

            PostListModel post_list = new PostListModel
            {
                posts = fetched_Posts,
                total_posts = total,
                cid_list = post_cid_list
            };

            return post_list;
        }
        public ActionResult GetPostList(PostListModel model) {
            var db = new ZkDataContext();
            model = model ?? new PostListModel();

            var thread = db.ForumThreads.First(x => x.ForumThreadID == model.ThreadID && (x.RestrictedClanID == null || x.RestrictedClanID == Global.ClanID));

            var posts = thread.ForumPosts.AsQueryable();

            if (!string.IsNullOrEmpty(model.Search))
            {
                posts = Global.ForumPostIndexer.FilterPosts(posts, model.Search);
            }
            if (!string.IsNullOrEmpty(model.User))
            {
                var filterAccountID = (db.Accounts.FirstOrDefault(x => x.Name == model.User) ?? db.Accounts.FirstOrDefault(x => x.Name.Contains(model.User)))?.AccountID;
                if (filterAccountID.HasValue) posts = posts.Where(x => x.AuthorAccountID == filterAccountID);
            }

            model.Data = posts.OrderBy(x=>x.ForumPostID);
            model.Thread = thread;

            return View("PostList", model);
        }