Exemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     blog_id = new Guid(Request["id"]);
     if (Request.Cookies["account_id"] != null)
     {
         user_id = new Guid(Request.Cookies["account_id"].Value);
     }
     else
     {
         Response.Write("<script type='text/javascript'>alert('你还没有登录!先去登录吧');location.href='/Views/Index/Index.aspx'</scritp>");
     }
     article = articleDao.GetSingle(blog_id);
     if (article == null)
     {
         Response.Write("<script type='text/javascript'>alert('这篇博客不翼而飞了!');location.href='/Views/Index/Index.aspx'</scritp>");
     }
     if (user_id != article.accountId)
     {
         Response.Write("<script type='text/javascript'>alert('兄弟你要修改别人的文章?');location.href='/Views/Index/Index.aspx'</scritp>");
     }
     if (!IsPostBack)
     {
         title.Text        = article.title;
         selecttype.Value  = article.category;
         mytag.InnerText   = article.tag;
         content.InnerText = article.content;
     }
 }
Exemplo n.º 2
0
 public Article GetArticle(Guid articleId)
 {
     return(dao.GetSingle(articleId));
 }
Exemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //初始化页面,根据url中的id获取文章内容
        //获取用户的登录状态
        string blog_id = Request["id"];

        id = new Guid(blog_id);
        //查询的评论时候要指定查询的文章id
        SqlDataSource1.SelectCommand = "SELECT comments.account_id, users.name, users.image, comments.content, comments.release_time FROM users INNER JOIN comments ON users.account_id = comments.account_id where article_id = '" + id + "'ORDER BY comments.release_time DESC";
        //绑定模糊查询的查询语句,查询相关文章的时候排除自己
        SqlDataSource2.SelectCommand = "select title,article_id from article where article_id != '" + id + "' and category = '" + article.category + "' order by likes desc limit 0,5";
        article = articleDao.GetSingle(id);
        if (article == null)
        {
            Response.Write("<script type='text/javascript'>alert('这篇博客不翼而飞了!');location.href='/Views/Index/Index.aspx'</scritp>");
        }
        user = userDao.GetSingle(article.accountId);
        this.blog_content.InnerText = article.content;
        if (Request.Cookies["account_id"] != null)
        {
            user_id = new Guid(Request.Cookies["account_id"].Value);
        }

        if (user_id == new Guid())
        {
            return;
        }
        //判断登录的用户是不是点赞过
        List <Like> likes = likeDao.GetListByAccount(user_id);

        foreach (Like like in likes)
        {
            if (like.articleId == id)
            {
                this.zan.Style.Add("background-color", "#00965e");
                this.zan.Style.Add("color", "white");
                this.zan_span.InnerText = "已赞";
            }
        }
        //判断登录的用户是不是收藏过
        List <Favorite> favorites = favoriteDao.GetListByAccount(user_id);

        foreach (Favorite favorite in favorites)
        {
            if (favorite.articleId == id)
            {
                this.shouchang.Style.Add("background-color", "#6c757d");
                this.shouchang.Style.Add("color", "white");
                this.shouchang_span.InnerText = "已收藏";
            }
        }
        //判断登录的用户是不是关注过作者或者就是作者本人
        if (article.accountId == user_id)
        {
            this.follow.Style.Add("display", "none");
        }
        List <Follow> follows = followDao.GetListByFan(user_id);

        foreach (Follow follow in follows)
        {
            if (follow.accountId == article.accountId)
            {
                this.follow.InnerText = "已关注";
            }
        }
    }