/// <summary>
        /// 自定义 特殊页面 公共方法
        /// </summary>
        /// <param name="str">BlogTitle名字</param>
        /// <param name="pageName">存在MyPageId的KEY名</param>
        private void Forum(string str, string pageName)
        {
            #region 检测是否存在 admin 用户

            if (adminuserid <= 0)
            {
                BLL.BlogUsersSetBLL userbll = new BLL.BlogUsersSetBLL();
                var user = userbll.GetList(t => t.UserName == admin).FirstOrDefault();
                if (null == user)
                {
                    var usertemp = new Blogs.ModelDB.BlogUsersSet()
                    {
                        UserName     = admin,
                        UserPass     = "******".MD5().MD5(),
                        IsDel        = false,
                        IsLock       = false,
                        UserNickname = "",
                        UserInfo     = new ModelDB.UserInfo()
                    };
                    userbll.Add(usertemp);
                    userbll.save(false);
                    adminuserid = usertemp.Id;
                }
                else
                {
                    adminuserid = user.Id;
                }
            }

            #endregion

            #region 是否存在 自定义 特殊页面 (返回 blogid)
            if (MyPageId[pageName] == 0)
            {
                BLL.BlogsBLL blogbll = new BLL.BlogsBLL();
                var          blog    = blogbll.GetList(t => t.BlogTitle == str).FirstOrDefault();
                if (null == blog)
                {
                    var blogtemp = new Blogs.ModelDB.Blogs()
                    {
                        Id        = 0,
                        UsersId   = adminuserid,
                        IsDel     = false,
                        BlogTitle = str
                    };
                    blogbll.Add(blogtemp);
                    blogbll.save(false);
                    CacheData.GetAllUserInfo(true);//更新缓存
                    MyPageId[pageName] = blogtemp.Id;
                }
                else
                {
                    MyPageId[pageName] = blog.Id;
                }
            }
            #endregion
        }
Example #2
0
        // GET api/<controller>
        public IEnumerable<string> Get()
        {
            Model1Container db = new Model1Container();
            db.Blogs.Where(t => t.BlogTitle == "留言板"
             ).ToList();

            BLL.BlogsBLL blogbll = new BLL.BlogsBLL();//|| t.BlogTitle.Contains(EntityFunctions.AsNonUnicode("取存过和函数"))
            var blogtemp = blogbll.GetList(t => t.BlogTitle == "留言板"
                || t.BlogTitle == "友情链接", isAsNoTracking: false).ToList();

            for (int i = 0; i < blogtemp.Count; i++)
            {
                blogtemp[i].BlogContent = "异常异fsdfs常异常";
            }
            blogbll.save();

            return new string[] { "value1", "value2", "admin".MD5().MD5(), "admin".MD5().MD5().MD5().MD5() };
        }
Example #3
0
        // GET api/<controller>
        public IEnumerable <string> Get()
        {
            Model1Container db = new Model1Container();

            db.Blogs.Where(t => t.BlogTitle == "留言板"
                           ).ToList();

            BLL.BlogsBLL blogbll  = new BLL.BlogsBLL();//|| t.BlogTitle.Contains(EntityFunctions.AsNonUnicode("取存过和函数"))
            var          blogtemp = blogbll.GetList(t => t.BlogTitle == "留言板" ||
                                                    t.BlogTitle == "友情链接", isAsNoTracking: false).ToList();

            for (int i = 0; i < blogtemp.Count; i++)
            {
                blogtemp[i].BlogContent = "异常异fsdfs常异常";
            }
            blogbll.save();


            return(new string[] { "value1", "value2", "admin".MD5().MD5(), "admin".MD5().MD5().MD5().MD5() });
        }
Example #4
0
        /// <summary>
        /// 转发
        /// </summary>
        public void Forward()
        {
            Response.ContentType = "application/json";
            var    ResultValue = string.Empty;
            var    data        = Request.QueryString["mydata"];
            string callback    = Request.QueryString["callback"];
            JavaScriptSerializer        jss = new JavaScriptSerializer();
            Dictionary <string, string> dic = jss.Deserialize <Dictionary <string, string> >(data);
            var    name     = dic["username"].Trim();
            var    pass     = dic["password"].Trim();
            var    userinfo = CacheData.GetAllUserInfo().Where(t => t.UserName == name && t.UserPass == pass.MD5().MD5()).FirstOrDefault();
            object tyeList  = null;

            if (userinfo != null)
            {
                var tag     = dic["tag"].Trim();
                var type    = dic["type"].Trim();
                var url     = dic["url"].Trim();
                int typeint = -1;
                int.TryParse(type, out typeint);
                var tags = tag.Split(',');

                var jp        = new JumonyParser();
                var html      = jp.LoadDocument(url);
                var titlehtml = html.Find(".postTitle a").FirstOrDefault().InnerHtml();
                titlehtml = "【转】" + titlehtml;
                var bodyhtml = html.Find("#cnblogs_post_body").FirstOrDefault().InnerHtml();
                bodyhtml += "</br><div class='div_zf'>==================================<a  href='" + url + "' target='_blank'>原文链接</a>==================================</div>";

                var mtag = BLL.Common.GetDataHelper.GetAllTag().Where(t => tags.Contains(t.TagName)).ToList();

                var blogtagid = new List <int>();
                for (int i = 0; i < tags.Length; i++)
                {
                    blogtagid.Add(this.GetTagId(tags[i], userinfo.Id));
                }
                //&& t.UsersId == userinfo.Id         理论是不用 加用户id 筛选
                var myBlogTags  = new BlogTagsBLL().GetList(t => blogtagid.Contains(t.Id), isAsNoTracking: false).ToList();
                var myBlogTypes = new BLL.BlogTypesBLL().GetList(t => t.Id == typeint, isAsNoTracking: false).ToList();

                object       obj       = null;
                string       call      = string.Empty;
                BLL.BlogsBLL blogbll   = new BLL.BlogsBLL();
                var          blogtitle = blogbll.GetList(t => t.UsersId == userinfo.Id).OrderByDescending(t => t.Id).FirstOrDefault().BlogTitle;
                if (blogtitle == titlehtml)
                {
                    obj  = new { s = "no", m = "已存在相同标题博客文章~", u = GetSiteUrl() };
                    call = callback + "('" + obj.ToJson() + "')";
                    Response.Write(call);
                    return;
                }

                var blogmode = new Blogs.ModelDB.Blogs()
                {
                    UsersId        = userinfo.Id,
                    BlogTitle      = titlehtml,
                    BlogTypes      = myBlogTypes,
                    BlogTags       = myBlogTags,
                    BlogContent    = bodyhtml,
                    CreateTime     = DateTime.Now,
                    BlogCreateTime = DateTime.Now,
                    BlogUpTime     = DateTime.Now,
                    IsShowMyHome   = true
                };

                blogbll.Add(blogmode);

                if (blogbll.save() > 0)
                {
                    obj  = new { s = "ok", m = "发布成功", u = GetSiteUrl() + "/" + userinfo.UserName + "/" + blogmode.Id + ".html" };
                    call = callback + "('" + obj.ToJson() + "')";
                    Response.Write(call);
                    return;
                }
                obj  = new { s = "no", m = "发布失败", u = GetSiteUrl() + "/" + userinfo.UserName + "/" + blogmode.Id + ".html" };
                call = callback + "('" + obj.ToJson() + "')";
                Response.Write(call);
                return;
            }
            else
            {
                var obj  = new { s = "no", m = "发布失败", u = GetSiteUrl() + "/" };
                var call = callback + "('" + obj.ToJson() + "')";
                Response.Write(call);
                return;
            }
            //var cc = callback + "('ok')";
            //Response.ContentType = "application/json";
            //Response.Write(cc);
        }
Example #5
0
        public string Release()
        {
            JSData jsdata = new JSData();

            var content      = Request.Form["content"];      //正文内容
            var title        = Request.Form["title"];        //标题
            var oldtag       = Request.Form["oldtag"];       //旧的标签
            var newtag       = Request.Form["newtag"];       //新的标签
            var types        = Request.Form["chk_type"];     //文章类型
            var isshowhome   = Request.Form["isshowhome"];   //是否显示在主页
            var isshowmyhome = Request.Form["isshowmyhome"]; //是否显示在个人主页
            var blogid       = Request.Form["blogid"];       //

            int numblogid = -1;

            int.TryParse(blogid, out numblogid);

            #region 数据验证
            if (null == BLL.Common.BLLSession.UserInfoSessioin)
            {
                jsdata.Messg = "您还未登录~";
            }
            else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock)
            {
                jsdata.Messg = "您的账户已经被锁定,请联系管理员~";
            }
            else if (string.IsNullOrEmpty(content))
            {
                jsdata.Messg = "内容不能为空~";
            }
            else if (content.Length >= 80000)
            {
                jsdata.Messg = "发布内容过多~";
            }
            else if (string.IsNullOrEmpty(title))
            {
                jsdata.Messg = "标题不能为空~";
            }
            else if (title.Length >= 100)
            {
                jsdata.Messg = "标题过长~";
            }

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

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

            //获取得 文章 类型集合 对象
            var typelist = new List <int>();
            foreach (string type in types.Split(',').ToList())
            {
                if (!string.IsNullOrEmpty(type))
                {
                    typelist.Add(int.Parse(type));
                }
            }
            // types.Split(',').ToList().ForEach(t => typelist.Add(int.Parse(t)));
            var myBlogTypes = new BLL.BlogTypesBLL().GetList(t => typelist.Contains(t.Id), isAsNoTracking: false).ToList();

            //获取得 文章 tag标签集合 对象
            //old
            var oldtaglist    = oldtag.Split(',').ToList();
            var myOldTagTypes = new BLL.BlogTagsBLL().GetList(t => t.UsersId == userid && oldtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            //new
            var newtaglist = newtag.Split(',').ToList();
            AddTag(newtaglist, userid);//保存到数据库
            var myNweTagTypes = new BLL.BlogTagsBLL().GetList(t => t.UsersId == userid && newtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            myNweTagTypes.ForEach(t => myOldTagTypes.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.UsersId || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户
                {
                    blogtemp.BlogContent = content;
                    blogtemp.BlogTitle   = title;
                    //blog.BlogUpTime = DateTime.Now;
                    //blog.BlogCreateTime = DateTime.Now;
                    blogtemp.IsShowMyHome = isshowmyhome == "true";
                    blogtemp.IsShowHome   = isshowhome == "true";
                    blogtemp.BlogTypes.Clear();//更新之前要清空      不如会存在主外键约束异常
                    blogtemp.BlogTypes = myBlogTypes;
                    blogtemp.BlogTags.Clear();
                    blogtemp.BlogTags     = myOldTagTypes;
                    blogtemp.IsDel        = false;
                    blogtemp.IsForwarding = false;
                    jsdata.Messg          = "修改成功~";
                }
                else
                {
                    jsdata.Messg = "您没有编辑此博文的权限~";
                    jsdata.JSurl = "/";
                    jsdata.State = EnumState.失败;
                    return(jsdata.ToJson());
                }
            }
            else  //否则 新增
            {
                var blogfirst = blogbll.GetList(t => t.UsersId == sessionuserid).OrderByDescending(t => t.Id).FirstOrDefault();
                //var blogtitle = blogtemp.BlogTitle;
                //if (blogfirst != null)
                //    blogtitle = blogtemp.BlogTitle;
                if (null != blogfirst && blogfirst.BlogTitle == title)
                {
                    jsdata.Messg = "不能同时发表两篇一样标题的文章~";
                }
                else
                {
                    blogtemp = new ModelDB.Blogs()
                    {
                        UsersId        = sessionuserid,
                        BlogContent    = content,
                        BlogTitle      = title,
                        BlogUpTime     = DateTime.Now,
                        BlogCreateTime = DateTime.Now,
                        IsShowMyHome   = isshowmyhome == "true",
                        IsShowHome     = isshowhome == "true",
                        BlogTypes      = myBlogTypes,
                        BlogTags       = myOldTagTypes,
                        IsDel          = false,
                        IsForwarding   = false
                    };
                    blogbll.Add(blogtemp);
                    jsdata.Messg = "发布成功~";
                }
            }

            //
            if (blogbll.save(false) > 0)
            {
                #region 添加 或 修改搜索索引
                try
                {
                    var newtagList = string.Empty;
                    blogtemp.BlogTags.Where(t => true).ToList().ForEach(t => newtagList += t.TagName + " ");
                    var          newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.Id + ".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);
                }
                catch (Exception)
                { }
                #endregion

                jsdata.State = EnumState.成功;
                jsdata.JSurl = "/" + CacheData.GetAllUserInfo().Where(t => t.Id == blogtemp.UsersId).First().UserName + "/" + blogtemp.Id + ".html";
                return(jsdata.ToJson());
            }

            jsdata.Messg = string.IsNullOrEmpty(jsdata.Messg) ? "操作失败~" : jsdata.Messg;
            jsdata.State = EnumState.失败;
            return(jsdata.ToJson());
        }
Example #6
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());
        }
Example #7
0
        /// <summary>
        /// 自定义 特殊页面 公共方法
        /// </summary>
        /// <param name="str">BlogTitle名字</param>
        /// <param name="pageName">存在MyPageId的KEY名</param>
        private void Forum(string str, string pageName)
        {
            #region 检测是否存在 admin 用户

            if (adminuserid <= 0)
            {
                BLL.BlogUsersSetBLL userbll = new BLL.BlogUsersSetBLL();
                var user = userbll.GetList(t => t.UserName == admin).FirstOrDefault();
                if (null == user)
                {
                    var usertemp = new Blogs.ModelDB.BlogUsersSet()
                    {
                        UserName = admin,
                        UserPass = "******".MD5().MD5(),
                        IsDel = false,
                        IsLock = false,
                        UserNickname = "",
                        UserInfo = new ModelDB.UserInfo()
                    };
                    userbll.Add(usertemp);
                    userbll.save(false);
                    adminuserid = usertemp.Id;
                }
                else
                    adminuserid = user.Id;
            }

            #endregion

            #region 是否存在 自定义 特殊页面 (返回 blogid)
            if (MyPageId[pageName] == 0)
            {
                BLL.BlogsBLL blogbll = new BLL.BlogsBLL();
                var blog = blogbll.GetList(t => t.BlogTitle == str).FirstOrDefault();
                if (null == blog)
                {
                    var blogtemp = new Blogs.ModelDB.Blogs()
                    {
                        Id = 0,
                        UsersId = adminuserid,
                        IsDel = false,
                        BlogTitle = str
                    };
                    blogbll.Add(blogtemp);
                    blogbll.save(false);
                    CacheData.GetAllUserInfo(true);//更新缓存
                    MyPageId[pageName] = blogtemp.Id;
                }
                else
                    MyPageId[pageName] = blog.Id;
            }
            #endregion
        }
Example #8
0
        public string Release()
        {
            JSData jsdata = new JSData();

            var content = Request.Form["content"];//正文内容
            var title = Request.Form["title"];//标题
            var oldtag = Request.Form["oldtag"];//旧的标签
            var newtag = Request.Form["newtag"];//新的标签
            var types = Request.Form["chk_type"];//文章类型
            var isshowhome = Request.Form["isshowhome"];//是否显示在主页
            var isshowmyhome = Request.Form["isshowmyhome"];//是否显示在个人主页
            var blogid = Request.Form["blogid"];//

            int numblogid = -1;
            int.TryParse(blogid, out numblogid);

            #region 数据验证
            if (null == BLL.Common.BLLSession.UserInfoSessioin)
                jsdata.Messg = "您还未登录~";
            else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock)
                jsdata.Messg = "您的账户已经被锁定,请联系管理员~";
            else if (string.IsNullOrEmpty(content))
                jsdata.Messg = "内容不能为空~";
            else if (content.Length >= 80000)
                jsdata.Messg = "发布内容过多~";
            else if (string.IsNullOrEmpty(title))
                jsdata.Messg = "标题不能为空~";
            else if (title.Length >= 100)
                jsdata.Messg = "标题过长~";

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

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

            //获取得 文章 类型集合 对象
            var typelist = new List<int>();
            foreach (string type in types.Split(',').ToList())
            {
                if (!string.IsNullOrEmpty(type))
                    typelist.Add(int.Parse(type));
            }
            // types.Split(',').ToList().ForEach(t => typelist.Add(int.Parse(t)));
            var myBlogTypes = new BLL.BlogTypesBLL().GetList(t => typelist.Contains(t.Id), isAsNoTracking: false).ToList();

            //获取得 文章 tag标签集合 对象
            //old
            var oldtaglist = oldtag.Split(',').ToList();
            var myOldTagTypes = new BLL.BlogTagsBLL().GetList(t => t.UsersId == userid && oldtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            //new
            var newtaglist = newtag.Split(',').ToList();
            AddTag(newtaglist, userid);//保存到数据库
            var myNweTagTypes = new BLL.BlogTagsBLL().GetList(t => t.UsersId == userid && newtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            myNweTagTypes.ForEach(t => myOldTagTypes.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.UsersId || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户
                {
                    blogtemp.BlogContent = content;
                    blogtemp.BlogTitle = title;
                    //blog.BlogUpTime = DateTime.Now;
                    //blog.BlogCreateTime = DateTime.Now;
                    blogtemp.IsShowMyHome = isshowmyhome == "true";
                    blogtemp.IsShowHome = isshowhome == "true";
                    blogtemp.BlogTypes.Clear();//更新之前要清空      不如会存在主外键约束异常
                    blogtemp.BlogTypes = myBlogTypes;
                    blogtemp.BlogTags.Clear();
                    blogtemp.BlogTags = myOldTagTypes;
                    blogtemp.IsDel = false;
                    blogtemp.IsForwarding = false;
                    jsdata.Messg = "修改成功~";
                }
                else
                {
                    jsdata.Messg = "您没有编辑此博文的权限~";
                    jsdata.JSurl = "/";
                    jsdata.State = EnumState.失败;
                    return jsdata.ToJson();
                }
            }
            else  //否则 新增
            {
                var blogfirst = blogbll.GetList(t => t.UsersId == sessionuserid).OrderByDescending(t => t.Id).FirstOrDefault();
                //var blogtitle = blogtemp.BlogTitle;
                //if (blogfirst != null)
                //    blogtitle = blogtemp.BlogTitle;
                if (null != blogfirst && blogfirst.BlogTitle == title)
                {
                    jsdata.Messg = "不能同时发表两篇一样标题的文章~";
                }
                else
                {
                    blogtemp = new ModelDB.Blogs()
                     {
                         UsersId = sessionuserid,
                         BlogContent = content,
                         BlogTitle = title,
                         BlogUpTime = DateTime.Now,
                         BlogCreateTime = DateTime.Now,
                         IsShowMyHome = isshowmyhome == "true",
                         IsShowHome = isshowhome == "true",
                         BlogTypes = myBlogTypes,
                         BlogTags = myOldTagTypes,
                         IsDel = false,
                         IsForwarding = false
                     };
                    blogbll.Add(blogtemp);
                    jsdata.Messg = "发布成功~";
                }
            }

            //
            if (blogbll.save(false) > 0)
            {
                #region 添加 或 修改搜索索引
                try
                {
                    var newtagList = string.Empty;
                    blogtemp.BlogTags.Where(t => true).ToList().ForEach(t => newtagList += t.TagName + " ");
                    var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.Id + ".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);
                }
                catch (Exception)
                { }
                #endregion

                jsdata.State = EnumState.成功;
                jsdata.JSurl = "/" + CacheData.GetAllUserInfo().Where(t => t.Id == blogtemp.UsersId).First().UserName + "/" + blogtemp.Id + ".html";
                return jsdata.ToJson();
            }

            jsdata.Messg = string.IsNullOrEmpty(jsdata.Messg) ? "操作失败~" : jsdata.Messg;
            jsdata.State = EnumState.失败;
            return jsdata.ToJson();
        }
Example #9
0
        static string siteUrl = string.Empty; // "blog.haojima.net";

        #endregion Fields

        #region Methods

        /// <summary>
        /// 转发
        /// </summary>
        public void Forward()
        {
            Response.ContentType = "application/json";
            var ResultValue = string.Empty;
            var data = Request.QueryString["mydata"];
            string callback = Request.QueryString["callback"];
            JavaScriptSerializer jss = new JavaScriptSerializer();
            Dictionary<string, string> dic = jss.Deserialize<Dictionary<string, string>>(data);
            var name = dic["username"].Trim();
            var pass = dic["password"].Trim();
            var userinfo = CacheData.GetAllUserInfo().Where(t => t.UserName == name && t.UserPass == pass.MD5().MD5()).FirstOrDefault();
            object tyeList = null;
            if (userinfo != null)
            {
                var tag = dic["tag"].Trim();
                var type = dic["type"].Trim();
                var url = dic["url"].Trim();
                int typeint = -1;
                int.TryParse(type, out typeint);
                var tags = tag.Split(',');

                var jp = new JumonyParser();
                var html = jp.LoadDocument(url);
                var titlehtml = html.Find(".postTitle a").FirstOrDefault().InnerHtml();
                titlehtml = "【转】" + titlehtml;
                var bodyhtml = html.Find("#cnblogs_post_body").FirstOrDefault().InnerHtml();
                bodyhtml += "</br><div class='div_zf'>==================================<a  href='" + url + "' target='_blank'>原文链接</a>==================================</div>";

                var mtag = BLL.Common.GetDataHelper.GetAllTag().Where(t => tags.Contains(t.TagName)).ToList();

                var blogtagid = new List<int>();
                for (int i = 0; i < tags.Length; i++)
                {
                    blogtagid.Add(this.GetTagId(tags[i], userinfo.Id));
                }
                //&& t.UsersId == userinfo.Id         理论是不用 加用户id 筛选
                var myBlogTags = new BlogTagsBLL().GetList(t => blogtagid.Contains(t.Id), isAsNoTracking: false).ToList();
                var myBlogTypes = new BLL.BlogTypesBLL().GetList(t => t.Id == typeint, isAsNoTracking: false).ToList();

                object obj = null;
                string call = string.Empty;
                BLL.BlogsBLL blogbll = new BLL.BlogsBLL();
                var blogtitle = blogbll.GetList(t => t.UsersId == userinfo.Id).OrderByDescending(t => t.Id).FirstOrDefault().BlogTitle;
                if (blogtitle == titlehtml)
                {
                    obj = new { s = "no", m = "已存在相同标题博客文章~", u = GetSiteUrl() };
                    call = callback + "('" + obj.ToJson() + "')";
                    Response.Write(call);
                    return;
                }

                var blogmode = new Blogs.ModelDB.Blogs()
                    {
                        UsersId = userinfo.Id,
                        BlogTitle = titlehtml,
                        BlogTypes = myBlogTypes,
                        BlogTags = myBlogTags,
                        BlogContent = bodyhtml,
                        CreateTime = DateTime.Now,
                        BlogCreateTime = DateTime.Now,
                        BlogUpTime = DateTime.Now,
                        IsShowMyHome = true
                    };

                blogbll.Add(blogmode);

                if (blogbll.save() > 0)
                {
                    obj = new { s = "ok", m = "发布成功", u = GetSiteUrl() + "/" + userinfo.UserName + "/" + blogmode.Id + ".html" };
                    call = callback + "('" + obj.ToJson() + "')";
                    Response.Write(call);
                    return;
                }
                obj = new { s = "no", m = "发布失败", u = GetSiteUrl() + "/" + userinfo.UserName + "/" + blogmode.Id + ".html" };
                call = callback + "('" + obj.ToJson() + "')";
                Response.Write(call);
                return;
            }
            else
            {
                var obj = new { s = "no", m = "发布失败", u = GetSiteUrl() + "/" };
                var call = callback + "('" + obj.ToJson() + "')";
                Response.Write(call);
                return;
            }
            //var cc = callback + "('ok')";
            //Response.ContentType = "application/json";
            //Response.Write(cc);
        }