/// <summary> /// 提交内容的编辑或修改 /// </summary> /// <param name="input"></param> /// <returns></returns> public JSData ReleasePost(ReleaseInput input) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLL.Common.BLLSession.UserInfoSessioin) { jsdata.Messg = "您还未登录~"; } else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock) { jsdata.Messg = "您的账户未激活,暂只能评论。~"; } else if (string.IsNullOrEmpty(input.Content)) { jsdata.Messg = "内容不能为空~"; } if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return(jsdata); } #endregion BLL.BaseBLL <BlogInfo> blogbll = new BaseBLL <BlogInfo>(); var blogtemp = blogbll.GetList(t => t.Id == input.Blogid, isAsNoTracking: false).FirstOrDefault(); var userid = input.Blogid > 0 ? blogtemp.User.Id : BLLSession.UserInfoSessioin.Id;//如果numblogid大于〇证明 是编辑修改 var sessionuserid = BLLSession.UserInfoSessioin.Id; //获取得 文章 类型集合 对象 var typelist = new List <int>(); if (!string.IsNullOrEmpty(input.Chk_type)) { foreach (string type in input.Chk_type.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.BaseBLL <BlogType>().GetList(t => typelist.Contains(t.Id), isAsNoTracking: false).ToList(); //获取得 文章 tag标签集合 对象 //old var oldtaglist = string.IsNullOrEmpty(input.Oldtag) ? new List <string>() : input.Oldtag.Split(',').ToList(); var myOldTagTypes = new BLL.BaseBLL <BlogTag>().GetList(t => t.BlogUser.Id == userid && oldtaglist.Contains(t.TagName), isAsNoTracking: false).ToList(); //new var newtaglist = input.Newtag.GetValueOrEmpty().Split(',').ToList(); AddTag(newtaglist, userid);//保存到数据库 var myNweTagTypes = new BLL.BaseBLL <BlogTag>().GetList(t => t.BlogUser.Id == userid && newtaglist.Contains(t.TagName), isAsNoTracking: false).ToList(); myNweTagTypes.ForEach(t => myOldTagTypes.Add(t)); if (input.Blogid > 0) //如果有 blogid 则修改 { if (sessionuserid == blogtemp.User.Id || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户 { blogtemp.Content = input.Content; blogtemp.Title = input.Title; blogtemp.IsShowMyHome = input.Isshowmyhome; blogtemp.IsShowHome = input.Isshowhome; blogtemp.Types.Clear();//更新之前要清空 不如会存在主外键约束异常 blogtemp.Types = myBlogTypes; blogtemp.Tags.Clear(); blogtemp.Tags = myOldTagTypes; blogtemp.IsDelte = false; blogtemp.IsForwarding = false; jsdata.Messg = "修改成功~"; } else { jsdata.Messg = "您没有编辑此博文的权限~"; jsdata.JSurl = "/"; jsdata.State = EnumState.失败; return(jsdata); } } else //否则 新增 { var blogfirst = blogbll.GetList(t => t.User.Id == sessionuserid).OrderByDescending(t => t.Id).FirstOrDefault(); if (null != blogfirst && blogfirst.Title == input.Title) { jsdata.Messg = "不能同时发表两篇一样标题的文章~"; } else { var bloguser = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == BLLSession.UserInfoSessioin.Id, isAsNoTracking: false).FirstOrDefault(); blogtemp = new BlogInfo() { User = bloguser, Content = input.Content, Title = input.Title, BlogUpTime = DateTime.Now, BlogCreateTime = DateTime.Now, IsShowMyHome = input.Isshowmyhome, IsShowHome = input.Isshowhome, Types = myBlogTypes, Tags = myOldTagTypes, IsDelte = false, IsForwarding = false }; blogbll.Insert(blogtemp); jsdata.Messg = "发布成功~"; } } // if (blogbll.save(false) > 0) { #region 添加 或 修改搜索索引 try { var newtagList = string.Empty; blogtemp.Tags.Where(t => true).ToList().ForEach(t => newtagList += t.TagName + " "); var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.Id + ".html"; SearchResult search = new SearchResult() { flag = blogtemp.User.Id, id = blogtemp.Id, title = blogtemp.Title, clickQuantity = 0, blogTag = newtagList, content = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.Content), url = newblogurl }; SafetyWriteHelper <SearchResult> .logWrite(search, PanGuLuceneHelper.instance.CreateIndex); } catch (Exception) { } #endregion jsdata.State = EnumState.成功; jsdata.JSurl = "/" + GetDataHelper.GetAllUser().Where(t => t.Id == blogtemp.User.Id).First().UserName + "/" + blogtemp.Id + ".html"; return(jsdata); } jsdata.Messg = string.IsNullOrEmpty(jsdata.Messg) ? "操作失败~" : jsdata.Messg; jsdata.State = EnumState.失败; return(jsdata); }