Exemplo n.º 1
0
        //public void Index()
        //{
        //    // 获取[文章]循环块,根据文章找标签
        //    DataPage<Article> articles = db.findPage<Article>("");
        //    IBlock block = getBlock("list");
        //    foreach (Article a in articles.Results)
        //    {
        //        block.Set("article.Title", a.Title);
        //        block.Set("article.ReadLink", to(new ArticleController().Read, a.Id));
        //        block.Set("article.Content", a.Content);
        //        block.Set("article.Created", a.Created);
        //        block.Set("article.ReadCount", a.ReadCount);


        //        block.Set("article.Tag.Name", a.Tag.Name);//删
        //        block.Set("article.ListLink", to(new ArticleController().List, a.Tag.Id));//删


        //        block.Next();
        //    }

        //    set("page", articles.PageBar);

        //}


        public void Index()
        {
            DataPage <Article>   articles       = db.findPage <Article>("");
            List <Tag>           tags           = Tag.findAll();
            List <ArticleAndTag> articleAndtags = ArticleAndTag.findAll();

            bindArticleAndTag(articles.Results, tags, articleAndtags);

            set("page", articles.PageBar);

            set("IndexLink", to(new MainController().Index));
        }
Exemplo n.º 2
0
        public void Read(int id)
        {
            HideLayout(typeof(wojilu.cms.xw.Controller.ArticleController));

            Article a = Article.findById(id);

            a.ReadCount++;
            db.update(a);
            bind("article", a);

            set("CommentLink", to(new ArticleController().SaveComment, id));//保存文章的评论到数据库中

            //ctx.SetItem( "article", a );
            //ctx.SetItem( "category", a.Category );

            //设置评论到Read页面
            string         sqlStr = string.Format("select * from Comment where ArticleId = {0} order by OrderBy asc", id);
            List <Comment> commentsByArticleId = db.findBySql <Comment>(sqlStr);

            IBlock blockComment = getBlock("listcomment");

            foreach (Comment comment in commentsByArticleId)
            {
                blockComment.Set("comment.OrderBy", comment.OrderBy);
                blockComment.Set("comment.Created", comment.Created);
                blockComment.Set("comment.BlogAddress", comment.BlogAddress);
                blockComment.Set("comment.UserName", comment.UserName);
                blockComment.Set("comment.Content", comment.Content);

                blockComment.Next();
            }

            //显示标签
            List <Tag>           tags           = Tag.findAll();
            List <ArticleAndTag> articleAndtags = ArticleAndTag.findAll();

            bindArticleAndTag(a, tags, articleAndtags);
        }