Пример #1
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();
        }
Пример #2
0
        public bool CreateIndex(IndexWriter writer, SearchResult data)
        {
            try
            {

                if (data == null) return false;
                Document doc = new Document();
                Type type = data.GetType();//assembly.GetType("Reflect_test.PurchaseOrderHeadManageModel", true, true); //命名空间名称 + 类名

                //创建类的实例
                //object obj = Activator.CreateInstance(type, true);
                //获取公共属性
                PropertyInfo[] Propertys = type.GetProperties();
                for (int i = 0; i < Propertys.Length; i++)
                {
                    //Propertys[i].SetValue(Propertys[i], i, null); //设置值
                    PropertyInfo pi = Propertys[i];
                    string name = pi.Name;
                    object objval = pi.GetValue(data, null);
                    string value = objval == null ? "" : objval.ToString(); //值
                    if (name == "id" || name == "flag")//id在写入索引时必是不分词,否则是模糊搜索和删除,会出现混乱
                    {
                        doc.Add(new Field(name, value, Field.Store.YES, Field.Index.NOT_ANALYZED));//id不分词
                    }
                    else
                    {
                        doc.Add(new Field(name, value, Field.Store.YES, Field.Index.ANALYZED));
                    }
                }
                writer.AddDocument(doc);
            }
            catch (System.IO.FileNotFoundException fnfe)
            {
                throw fnfe;
            }
            return true;
        }
Пример #3
0
 public bool Delete(SearchResult ids)
 {
     return Delete(ids.id.ToString());
 }
Пример #4
0
 public bool CreateIndex(SearchResult data)
 {
     List<SearchResult> datalist = new List<SearchResult>();
     datalist.Add(data);
     return CreateIndex(datalist);
 }