/// <summary>
        /// (弃用)
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="sizePage">页容量</param>
        /// <param name="ContentLength">内容截取长度</param>
        /// <returns></returns>
        public object Get(int idex, int sizePage, int ContentLength)
        {
            int total;

            BLL.BlogsBLL blog     = new BLL.BlogsBLL();
            var          bloglist = blog.GetList(idex, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false, tableName: t => t.BlogUsersSet)//
                                    .ToList()
                                    .Select(t => new ModelDB.Blogs()
            {
                Id             = t.Id,
                BlogTitle      = t.BlogTitle,
                BlogContent    = MyHtmlHelper.GetHtmlText(t.BlogContent, ContentLength),
                BlogCreateTime = t.BlogCreateTime,
                BlogUsersSet   = new ModelDB.BlogUsersSet()
                {
                    UserName     = t.BlogUsersSet.UserName,
                    UserNickname = t.BlogUsersSet.UserNickname
                },
                BlogReadNum    = t.BlogReadNum,
                BlogCommentNum = t.BlogCommentNum
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("blog", bloglist);
            dic.Add("total", total);
            //dic.Add("users", CacheData.GetAllUserInfo().Where(t => t.IsLock == false).ToList());
            //dic.Add("SessionUser", BLL.Common.BLLSession.UserInfoSessioin);
            return(dic);
        }
        /// <summary>
        /// 分页获取 博客 内容
        /// </summary>
        /// <param name="idex">页码</param>
        /// <param name="sizePage">页容量</param>
        /// <param name="ContentLength">内容截取长度</param>
        /// <returns></returns>
        public object GetBlogContent(int index, int sizePage, int contentLength)
        {
            int total;

            BLL.BlogsBLL blog     = new BLL.BlogsBLL();
            var          bloglist = blog.GetList(index, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false, tableName: t => t.BlogUsersSet)//
                                    .ToList()
                                    .Select(t => new ModelDB.Blogs()
            {
                Id             = t.Id,                                                   //博客id
                BlogTitle      = t.BlogTitle,                                            //博客标题
                BlogContent    = MyHtmlHelper.GetHtmlText(t.BlogContent, contentLength), //博客简介
                BlogCreateTime = t.BlogCreateTime,                                       //博客创建时间
                BlogUsersSet   = new ModelDB.BlogUsersSet()
                {
                    UserName     = t.BlogUsersSet.UserName,    //用户名
                    UserNickname = t.BlogUsersSet.UserNickname //昵称
                },
                BlogReadNum    = t.BlogReadNum,                //博客阅读量
                BlogCommentNum = t.BlogCommentNum              //博客评论量
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("BlogBrief", bloglist); //博客简介
            dic.Add("Total", total);        //总页数
            //dic.Add("users", CacheData.GetAllUserInfo().Where(t => t.IsLock == false).Select(t => new
            //    {
            //        UserName = t.UserName,
            //        UserImage = t.UserImage,
            //        UserNickname = t.UserNickname
            //    }
            //    ).ToList());
            return(dic);
        }
Beispiel #3
0
        public ActionResult Index(int?id)
        {
            //
            int total;

            Response.Cache.SetOmitVaryStar(true);
            id = id ?? 1;
            int idex = int.Parse(id.ToString());

            BLL.BlogsBLL blog     = new BLL.BlogsBLL();
            var          bloglist = blog.GetList <DateTime?>(idex, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false)
                                    .Select(t => new
            {
                Id             = t.Id,
                BlogTitle      = t.BlogTitle,
                BlogContent    = t.BlogContent,
                UserName       = t.BlogUsersSet.UserName,
                UserNickname   = t.BlogUsersSet.UserNickname,
                BlogCreateTime = t.BlogCreateTime,
                BlogReadNum    = t.BlogReadNum,
                BlogCommentNum = t.BlogCommentNum
            })
                                    .ToList()
                                    .Select(t => new ModelDB.Blogs()
            {
                Id             = t.Id,
                BlogTitle      = t.BlogTitle,
                BlogContent    = MyHtmlHelper.GetHtmlText(t.BlogContent),
                BlogCreateTime = t.BlogCreateTime,
                BlogUsersSet   = new ModelDB.BlogUsersSet()
                {
                    UserName     = t.UserName,
                    UserNickname = t.UserNickname
                },
                BlogReadNum    = t.BlogReadNum,
                BlogCommentNum = t.BlogCommentNum
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("blog", bloglist);
            dic.Add("users", CacheData.GetAllUserInfo().Where(t => t.IsLock == false).ToList());
            dic.Add("SessionUser", BLL.Common.BLLSession.UserInfoSessioin);
            dic.Add("total", total);
            return(View(dic));
        }
Beispiel #4
0
        public ActionResult GetTagBlogs(int id, string name, int?typeId)
        {
            Response.Cache.SetOmitVaryStar(true);
            BLL.BaseBLL <BlogTag> tagbll = new BLL.BaseBLL <BlogTag>();
            var tag = tagbll.GetList(t => t.Id == typeId && t.BlogUser.UserName == name).FirstOrDefault();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            if (tag != null)
            {
                //这里因为 是直接 分页查询        所以一定要记住 过滤 isdel
                var listblog = tag.BlogInfos.Where(t => t.IsDelte == false).OrderByDescending(t => t.BlogCreateTime).Skip((id - 1) * sizePage).Take(sizePage)
                               .Select(t => new
                {
                    BlogContent    = t.Content,
                    BlogCreateTime = t.BlogCreateTime,
                    BlogTitle      = t.Title,
                    Id             = t.Id,
                    BlogReadNum    = t.ReadNum,
                    BlogCommentNum = t.CommentNum
                })
                               .ToList()
                               .Select(t => new BlogInfo()
                {
                    Id             = t.Id,
                    Title          = t.BlogTitle,
                    BlogCreateTime = t.BlogCreateTime,
                    Content        = MyHtmlHelper.GetHtmlText(t.BlogContent),
                    ReadNum        = t.BlogReadNum,
                    CommentNum     = t.BlogCommentNum
                })
                               .ToList();
                dic.Add("blog", listblog);
                dic.Add("tag", tag.TagName);

                int mcount = tag.BlogInfos.Count();
                int total  = (mcount / sizePage) + (mcount % sizePage > 0 ? 1 : 0);
                dic.Add("total", total);

                SetDic(dic, name);
                return(View(dic));
            }
            return(View());
        }
        public ActionResult GetTypeBlogs(int id, string name, int?typeId)
        {
            Response.Cache.SetOmitVaryStar(true);
            BLL.BlogTypesBLL typebll = new BLL.BlogTypesBLL();
            var type = typebll.GetList(t => t.Id == typeId && t.BlogUsersSet.UserName == name).FirstOrDefault();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            if (type != null)
            {
                var listblog = type.Blogs.Where(t => t.IsDel == false).OrderByDescending(t => t.BlogCreateTime).Skip((id - 1) * sizePage).Take(sizePage)
                               .Select(t => new
                {
                    BlogCreateTime = t.BlogCreateTime,
                    BlogContent    = t.BlogContent,
                    BlogTitle      = t.BlogTitle,
                    Id             = t.Id,
                    BlogReadNum    = t.BlogReadNum,
                    BlogCommentNum = t.BlogCommentNum
                })
                               .ToList()
                               .Select(t => new ModelDB.Blogs()
                {
                    Id             = t.Id,
                    BlogTitle      = t.BlogTitle,
                    BlogCreateTime = t.BlogCreateTime,
                    BlogContent    = MyHtmlHelper.GetHtmlText(t.BlogContent),
                    BlogReadNum    = t.BlogReadNum,
                    BlogCommentNum = t.BlogCommentNum
                })
                               .ToList();
                dic.Add("blog", listblog);
                dic.Add("type", type.TypeName);

                int mcount = type.Blogs.Count();
                int total  = (mcount / sizePage) + (mcount % sizePage > 0 ? 1 : 0);
                dic.Add("total", total);

                SetDic(dic, name);
                return(View(dic));
            }
            return(View());
        }
Beispiel #6
0
        public ActionResult UserBlogList(string name, int?id)
        {
            //加不加 Response.Cache.SetOmitVaryStar(true),服务端的缓存情况都是一样的。
            //只是不加 SetOmitVaryStar(true) 时,对于同一个客户端浏览器,每隔一次请求,服务器端就不管客户端浏览器的缓存,
            //重新发送页面内容,但是只要在缓存有效期内,内容还是从服务器端缓存中读取。
            //http://www.cnblogs.com/dudu/archive/2012/08/27/asp_net_mvc_outputcache.html
            Response.Cache.SetOmitVaryStar(true);
            int myid = id ?? 1;

            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();
            var bloglist = blog.GetList <DateTime?>(myid, sizePage, out total, t => t.User.UserName == name && t.IsShowMyHome == true, false, t => t.BlogCreateTime, false)
                           .Select(t => new
            {
                Id             = t.Id,
                BlogTitle      = t.Title,
                BlogContent    = t.Content,
                BlogCreateTime = t.BlogCreateTime,
                BlogReadNum    = t.ReadNum,
                BlogCommentNum = t.CommentNum
            })
                           .ToList()
                           .Select(t => new BlogInfo()
            {
                Id             = t.Id,
                Title          = t.BlogTitle,
                Content        = MyHtmlHelper.GetHtmlText(t.BlogContent),
                BlogCreateTime = t.BlogCreateTime,
                ReadNum        = t.BlogReadNum,
                CommentNum     = t.BlogCommentNum
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("blogList", bloglist);
            //dic.Add("blogUserName", name);
            dic.Add("total", total);
            SetDic(dic, name);
            return(View(dic));
        }
        [CacheOutput(ClientTimeSpan = 120, ServerTimeSpan = 120)]//120 两分钟
        public object GetBlogContent(int index, int sizePage, int contentLength, int userId = -1)
        {
            int total;

            BLL.BaseBLL <BlogInfo> blog         = new BLL.BaseBLL <BlogInfo>();
            IQueryable <BlogInfo>  bloglistTemp = null;

            if (userId > 0)//个人用户首页
            {
                bloglistTemp = blog.GetList(index, sizePage, out total, t => t.IsShowMyHome == true && t.User.Id == userId, false, t => t.BlogCreateTime, false, tableName: t => t.User);
            }
            else//首页
            {
                bloglistTemp = blog.GetList(index, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false, tableName: t => t.User);//
            }
            var bloglist = bloglistTemp.ToList()
                           .Select(t => new BlogInfo()
            {
                Id             = t.Id,                                               //博客id
                Title          = t.Title,                                            //博客标题
                Content        = MyHtmlHelper.GetHtmlText(t.Content, contentLength), //博客简介
                BlogCreateTime = t.BlogCreateTime,                                   //博客创建时间
                User           = new BlogUser()
                {
                    UserName     = t.User.UserName,    //用户名
                    UserNickname = t.User.UserNickname //昵称
                },
                ReadNum    = t.ReadNum,                //博客阅读量
                CommentNum = t.CommentNum              //博客评论量
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("BlogBrief", bloglist); //博客简介
            dic.Add("Total", total);        //总页数
            return(dic);
        }
Beispiel #8
0
        public string Release()
        {
            JSData jsdata = new JSData();

            var content    = Request.Form["content"];    //正文内容
            var title      = Request.Form["title"];      //标题
            var oldtag     = Request.Form["oldtag"];     //旧的标签(从checkbox中选取的)
            var newtag     = Request.Form["newtag"];     //新的标签(在tag_text中输入的)
            var type       = Request.Form["chk_type"];   //文章类型
            var isshowhome = Request.Form["isshowhome"]; //是否显示在主页
            var blogid     = Request.Form["blogid"];     //

            int numblogid = -1;

            int.TryParse(blogid, out numblogid);

            #region 数据验证
            if (null == BLL.Common.BLLSession.UserInfoSessioin)
            {
                jsdata.Message = "您还未登录~";
            }

            /*else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock)
             *  jsdata.Message = "您的账户未激活,暂只能评论。~";*/
            else if (string.IsNullOrEmpty(content))
            {
                jsdata.Message = "内容不能为空~";
            }
            else if (content.Length >= 300000)
            {
                jsdata.Message = "发布内容过多~";
            }
            else if (string.IsNullOrEmpty(title))
            {
                jsdata.Message = "标题不能为空~";
            }
            else if (title.Length >= 100)
            {
                jsdata.Message = "标题过长~";
            }

            if (!string.IsNullOrEmpty(jsdata.Message))
            {
                jsdata.State = EnumState.失败;
                return(jsdata.ToJson());
            }
            #endregion

            BLL.BlogsBLL blogbll       = new BLL.BlogsBLL();
            var          blogtemp      = blogbll.GetList(t => t.BlogId == numblogid, isAsNoTracking: false).FirstOrDefault();
            var          userid        = numblogid > 0 ? blogtemp.UserId : BLLSession.UserInfoSessioin.UserId;//如果numblogid大于〇证明 是编辑修改
            var          sessionuserid = BLLSession.UserInfoSessioin.UserId;

            //获取得 文章 类型
            BlogTypes myBlogType;
            if (type == null)
            {
                myBlogType = new BlogTypesBLL().GetList(t => (t.TypeName == "未分类" && t.UserId == BLLSession.UserInfoSessioin.UserId), isAsNoTracking: false).FirstOrDefault();
            }
            else
            {
                var blogtype = int.Parse(type);
                myBlogType = new BLL.BlogTypesBLL().GetList(t => t.BlogTypeId == blogtype, isAsNoTracking: false).ToList().FirstOrDefault();
            }
            //获取得 文章 tag标签集合 对象
            //old
            var oldtaglist = oldtag.Split(',').ToList();
            var myOldTag   = new BLL.BlogTagsBLL().GetList(t => t.UserId == userid && oldtaglist.Contains(t.BlogTagName), isAsNoTracking: false).ToList();
            //new
            var newtaglistname = newtag.Split(',').ToList();

            //保存newtags到数据库
            BlogTagsBLL   tagBLL       = new BlogTagsBLL();
            List <string> distinctTemp = new List <string>();
            foreach (string tagName in newtaglistname)
            {
                if (String.IsNullOrEmpty(tagName.Trim()))
                {
                    continue;
                }
                if (distinctTemp.Contains(tagName.Trim()))
                {
                    continue;
                }
                tagBLL.Add(new BlogTags
                {
                    BlogTagName = tagName.Trim(),
                    UserId      = userid
                });
                try { tagBLL.save(); }
                catch (Exception ex)
                {
                    jsdata.Message = ex.ToString();
                    jsdata.State   = EnumState.失败;
                    return(jsdata.ToJson());
                }
                distinctTemp.Add(tagName.Trim());
                BLL.DataCache.GetAllTag(true);
            }
            //////////////////////

            var myTags = new BLL.BlogTagsBLL().GetList(t => t.UserId == userid && newtaglistname.Contains(t.BlogTagName), isAsNoTracking: false).ToList();
            myOldTag.ForEach(t => myTags.Add(t));



            //ModelDB.Blogs blogtemp = new ModelDB.Blogs();
            if (numblogid > 0)  //如果有 blogid 则修改
            {
                //blog = blogbll.GetList(t => t.Id == numblogid, isAsNoTracking: false).FirstOrDefault();
                if (sessionuserid == blogtemp.UserId || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户
                {
                    blogtemp.Content     = content;
                    blogtemp.BlogRemarks = MyHtmlHelper.GetHtmlText(content);
                    blogtemp.Title       = title;
                    blogtemp.IsShowHome  = isshowhome == "true";
                    blogtemp.BlogTypes   = myBlogType;
                    blogtemp.BlogTags.Clear();//更新之前要清空      否则会存在主外键约束异常
                    blogtemp.BlogTags     = myTags;
                    blogtemp.IsDel        = false;
                    blogtemp.IsForwarding = false;
                    jsdata.Message        = "修改成功~";
                }
                else
                {
                    jsdata.Message = "您没有编辑此博文的权限~";
                    jsdata.JSurl   = "/";
                    jsdata.State   = EnumState.失败;
                    return(jsdata.ToJson());
                }
            }
            else  //否则是新发布
            {
                var blogfirst = blogbll.GetList(t => t.UserId == sessionuserid).OrderByDescending(t => t.BlogId).FirstOrDefault();
                //var blogtitle = blogtemp.BlogTitle;
                //if (blogfirst != null)
                //    blogtitle = blogtemp.BlogTitle;
                if (null != blogfirst && blogfirst.Title == title)
                {
                    jsdata.Message = "不能同时发表两篇一样标题的文章~";
                }
                else
                {
                    blogtemp = new Blogs()
                    {
                        UserId       = sessionuserid,
                        Content      = content,
                        BlogRemarks  = MyHtmlHelper.GetHtmlText(content),
                        Title        = title,
                        IsShowHome   = isshowhome == "true",
                        BlogTypes    = myBlogType,
                        BlogTags     = myTags,
                        IsDel        = false,
                        IsForwarding = false
                    };
                    blogbll.Add(blogtemp);
                    jsdata.Message = "发布成功~";
                }
            }

            //
            try
            {
                if (blogbll.save(false) > 0)
                {
                    blogtemp.BlogUrl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.BlogId + ".html";
                    blogbll.save();
                    BLL.DataCache.GetAllType(true);
                    #region 添加 或 修改搜索索引

                    var newtagList = string.Empty;
                    blogtemp.BlogTags.Where(t => true).ToList().ForEach(t => newtagList += t.BlogTagName + " ");
                    var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.BlogId + ".html";
                    //    SearchResult search = new SearchResult()
                    //    {
                    //        flag = blogtemp.UsersId,
                    //        id = blogtemp.Id,
                    //        title = blogtemp.BlogTitle,
                    //        clickQuantity = 0,
                    //        blogTag = newtagList,
                    //        content = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.BlogContent),
                    //        url = newblogurl
                    //    };
                    //    SafetyWriteHelper<SearchResult>.logWrite(search, PanGuLuceneHelper.instance.CreateIndex);
                    //

                    #endregion
                    jsdata.State = EnumState.成功;
                    jsdata.JSurl = "/" + DataCache.GetUsersInfo().Where(t => t.UserId == blogtemp.UserId).First().UserName + "/" + blogtemp.BlogId + ".html";
                    return(jsdata.ToJson());
                }
            }
            catch (Exception ex)
            {
                jsdata.State   = EnumState.失败;
                jsdata.Message = ex.ToString();
                return(jsdata.ToJson());
            }

            jsdata.State = EnumState.失败;
            return(jsdata.ToJson());
        }
Beispiel #9
0
        /// <summary>
        /// 根据博客id 获取博客
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public Dictionary <string, object> GetUserBlog(string name, int id)
        {
            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();

            #region 优化前
            //var blogobj = blog.GetList(t => t.Id == id && t.Users.UserName == name).FirstOrDefault();

            ////这里看 能不能只查询一次
            //var blogNext = blog.GetList(t => t.Id > id && t.Users.UserName == name).OrderBy(t => t.Id).FirstOrDefault();
            //var blogLast = blog.GetList(t => t.Id < id && t.Users.UserName == name).OrderBy(t => t.Id).FirstOrDefault();
            #endregion

            //优化后 只查一次数据库
            //比如id 为3 那么 last取3,4  next取2,3
            var last = blog.GetList(t => t.Id >= id && t.User.UserName == name, isAsNoTracking: false, tableName: t => t.User).OrderBy(t => t.Id).Take(2);
            var next = blog.GetList(t => t.Id <= id && t.User.UserName == name, isAsNoTracking: false, tableName: t => t.User).OrderByDescending(t => t.Id).Take(2);
            //去重复合并
            var blogUnion = (from c in last select c).Union(from a in next select a).ToList();

            var blogNext = blogUnion.Where(t => t.Id > id).FirstOrDefault();
            var blogLast = blogUnion.Where(t => t.Id < id).FirstOrDefault();
            var blogobj  = blogUnion.Where(t => t.Id == id).FirstOrDefault();

            Dictionary <string, object> dic = new Dictionary <string, object>();
            dic.Add("blog", blogobj);
            dic.Add("blogNext", blogNext);
            dic.Add("blogLast", blogLast);
            dic.Add("contentBlogType", blogobj.Types == null ? new List <BlogType>() : blogobj.Types.ToList()); //当前博客所属的类型
            dic.Add("contentBlogTag", blogobj.Tags == null ? new List <BlogTag>() : blogobj.Tags.ToList());     //当前博客所有的tag标签

            //Description 网页描述
            var BlogContent = MyHtmlHelper.GetHtmlText(blogobj.Content);
            BlogContent = BlogContent.Length >= 300 ? BlogContent.Substring(0, 300) : BlogContent;
            dic.Add("blogConText", BlogContent);

            SetDic(dic, name);

            #region 保存 标记 此文已经阅读过
            var        BlogReadInfo = "BlogReadInfo";
            HttpCookie Cookie       = CookiesHelper.GetCookie(BlogReadInfo);
            if (null == Cookie)
            {
                Cookie = new HttpCookie(BlogReadInfo);
                Cookie.Values.Add(blogobj.Id.ToString(), "true");
                //设置Cookie过期时间
                Cookie.Expires = DateTime.Now.AddHours(24);//一天
                CookiesHelper.AddCookie(Cookie);
                //........................异步调用....................
                new SaveReadDelegate(SaveReadNum).BeginInvoke(blogobj, GetUserDistinguish(Request), null, null);
            }
            else
            {
                if (Cookie.Values[blogobj.Id.ToString()] == null || !Cookie.Values[blogobj.Id.ToString()].Equals("true"))
                {
                    CookiesHelper.SetCookie(BlogReadInfo, blogobj.Id.ToString(), "true");
                    //........................异步调用....................
                    new SaveReadDelegate(SaveReadNum).BeginInvoke(blogobj, GetUserDistinguish(Request), null, null);
                }
            }
            #endregion

            return(dic);
        }