public ActionResult ToKnowledgeModify(string ariticleId)
 {
     using (RRDLEntities db = new RRDLEntities())
     {
         AriticleService ars = new AriticleService(db);
         Ariticle ariticle = ars.FindById(ariticleId);
         AriticleViewModel avm = new AriticleViewModel(ariticle);
         List<AriticleVisibility> visibilityList = ars.GetAriticleVisibility(ariticle.Id);
         avm.Id = ariticle.Id;
         string result = JsonConvert.SerializeObject(avm);
         ViewBag.Ariticle = result;
         UserGroupService ugs = new UserGroupService();
         List<UserGroup> list = ugs.FindAll();
         List<UserGroupViewModel> ugvlist = new List<UserGroupViewModel>();
         UserGroupViewModel ugv;
         for (int i = 0; i < list.Count; i++)
         {
             ugv = new UserGroupViewModel(list[i]);
             ugvlist.Add(ugv);
         }
         string resultlist = JsonConvert.SerializeObject(ugvlist);
         ViewBag.OpenString = resultlist;
         Tree tree = new Tree();
         TreeNode treeNode = tree.SearchByAriticle(ariticle.Id);
         List<TreeNode> treelist = tree.GetTreeNodePath(treeNode);
         string treeresult = "";
         for (int i = treelist.Count - 1; i >= 0; i--)
         {
             treeresult = treeresult + treelist[i].Title + "TreePathSplit";
         }
         ViewBag.TreeId = treeNode.ParentId;
         ViewBag.TreePath = treeresult;
         VisibilityViewModel vvm = new VisibilityViewModel();
         List<VisibilityViewModel> vvlist = new List<VisibilityViewModel>();
         int count = ugs.FindAll().Count;
         if (count == visibilityList.Count)
         {
             ViewBag.visibilityList = "all";
         }
         else
         {
             for (int i = 0; i < visibilityList.Count; i++)
             {
                 vvm = new VisibilityViewModel();
                 vvm.Id = visibilityList[i].Id;
                 vvm.UserGroupId = visibilityList[i].UserGroupId;
                 vvlist.Add(vvm);
             }
             string vlist = JsonConvert.SerializeObject(vvlist);
             ViewBag.visibilityList = vlist;
         }
         string author = ariticle.User.NickName;
         string createTime = ariticle.Createtime.ToString();
         ViewBag.author = author;
         ViewBag.createTime = createTime;
         return View();
     }
 }
        public string KnowledgeModify(string ariticleJson)
        {
            using (RRDLEntities db = new RRDLEntities())
            {
                AriticleJson ariticlejson = (AriticleJson)JsonConvert.DeserializeObject(ariticleJson, typeof(AriticleJson));

                AriticleService ars = new AriticleService(db);
                Ariticle ariticle = ars.FindById(ariticlejson.Id);

                //添加标题
                ariticle.Title = ariticlejson.title;
                //添加内容
                //ariticle.UGC = System.Web.HttpUtility.UrlDecode(ariticlejson.UGC);
                ariticlejson.UGC = System.Web.HttpUtility.UrlDecode(ariticlejson.UGC);
                ariticlejson.UGC = ariticlejson.UGC.Replace("CodeReplacePlus", "+");
                ariticle.UGC = ariticlejson.UGC;
                //添加标签
                string[] tlist = ariticlejson.tag.Split(new char[] { ',' });
                List<AriticleTag> tagList = new List<AriticleTag>();
                for (int i = 0; i < tlist.Length; i++)
                {
                    AriticleTag ariticletag = new AriticleTag();
                    ariticletag.Title = tlist[i];
                    ariticletag.AriticleId = ariticlejson.Id;
                    // ariticletag.Article = ariticle;
                    tagList.Add(ariticletag);
                }
                AriticleTagRepository tagRepository = new AriticleTagRepository(db);
                tagRepository.UpdateAllRelatedAriticleId(ariticle.Id, tagList);
                //创建一个新节点
                TreeNode treeNode = new TreeNode(Int32.Parse(ariticlejson.treeNodeParentId), ariticlejson.title);
                treeNode.Ariticle = ariticle;
                Tree tree = new Tree(db);
                tree.AddTreeNode(treeNode);
                //删除旧节点
                TreeNode oldtreeNode = tree.SearchByAriticle(ariticle.Id);
                tree.Drop(oldtreeNode);
                //创建不可见分组信息数组
                string[] inlist = ariticlejson.invisibility.Split(new char[] { ';' });
                List<int> invisiblityGroup = new List<int>();
                for (int i = 0; i < inlist.Length - 1; i++)
                {
                    invisiblityGroup.Add(Int32.Parse(inlist[i]));
                }
                //判断是否为管理员或超级管理员修改,审核状态保持已通过审核
                UserService us = new UserService();
                User user = us.FindById(ariticlejson.UserId);
                if (user.AuthorityCategory != EnumUserCategory.Administrator && user.AuthorityCategory != EnumUserCategory.Superman)
                {
                    ariticle.Approve.ApproveStatus = EnumAriticleApproveStatus.UnApproved;
                }
                else {
                    ariticle.Approve.ApproveStatus = EnumAriticleApproveStatus.Approved;
                }
                ars.UpdateAriticle(ariticle, invisiblityGroup);
                db.SaveChanges();
                return "success";
            }
        }
 public string GetSystemMessage(string ariticleId) {
     using (RRDLEntities db = new RRDLEntities())
     {
         AriticleService ars = new AriticleService(db);
         Ariticle ariticle = ars.FindById(ariticleId);
         string replay = ariticle.Approve.ReplyContent;                
         return replay;
     }
 }
 //根据传进来的id查到此条知识的详细信息,并返回JSON
 public string GetKnowledgeDetails(string ariticleId)
 {
     //using (RRDLEntities db = new RRDLEntities())
     //{
     //    AriticleService ariticleservice = new AriticleService();
     //    Ariticle ariticle = ariticleservice.FindById(ariticleId);
     //    AriticleViewModel art = new AriticleViewModel(ariticle);
     //    string result = JsonConvert.SerializeObject(art);
     //    return result;
     //}
     using (RRDLEntities db = new RRDLEntities())
     {
         AriticleService ars = new AriticleService(db);
         Ariticle ariticle = ars.FindById(ariticleId);
         AriticleViewModel avm = new AriticleViewModel(ariticle);
         //avm.Title = ariticle.Title;
         //avm.UGC = ariticle.UGC;
         string result = JsonConvert.SerializeObject(avm);
         return result;
     }
 }
 public string KnowledgeModify(string title, string userId, string invisibility, string tag, string content, string ariticleId, string treeNodeParentId)
 {
     using (RRDLEntities db = new RRDLEntities())
     {
         AriticleService ars = new AriticleService(db);
         Ariticle ariticle = ars.FindById(ariticleId);
       
         //添加标题
         ariticle.Title = title;
         //添加内容
         //ariticle.UGC = System.Web.HttpUtility.UrlDecode(content);
         content = System.Web.HttpUtility.UrlDecode(content);
         content = content.Replace("CodeReplacePlus", "+");
         ariticle.UGC = content;
         //添加标签
         string[] tlist = tag.Split(new char[] { ',' });
         List<AriticleTag> tagList = new List<AriticleTag>();
         for (int i = 0; i < tlist.Length; i++)
         {
             AriticleTag ariticletag = new AriticleTag();
             ariticletag.Title = tlist[i];
             ariticletag.AriticleId = ariticleId;
             // ariticletag.Article = ariticle;
             tagList.Add(ariticletag);
         }
         AriticleTagRepository tagRepository = new AriticleTagRepository(db);
         tagRepository.UpdateAllRelatedAriticleId(ariticle.Id, tagList);
         //创建一个新节点
         TreeNode treeNode = new TreeNode(Int32.Parse(treeNodeParentId), title);
         treeNode.Ariticle = ariticle;
         Tree tree = new Tree(db);
         tree.AddTreeNode(treeNode);
         //删除旧节点
         TreeNode oldtreeNode = tree.SearchByAriticle(ariticle.Id);
         tree.Drop(oldtreeNode);
         //创建不可见分组信息数组
         string[] inlist = invisibility.Split(new char[] { ';' });
         List<int> invisiblityGroup = new List<int>();
         for (int i = 0; i < inlist.Length - 1; i++)
         {
             invisiblityGroup.Add(Int32.Parse(inlist[i]));
         }
         ariticle.Approve.ApproveStatus = EnumAriticleApproveStatus.Approved;
         ars.UpdateAriticle(ariticle, invisiblityGroup);
         db.SaveChanges();
         return "success";
     }
 }
 public ActionResult GetAriticleById(string ariticleId)
 {
     using (RRDLEntities db = new RRDLEntities())
     {
         AriticleService ars = new AriticleService(db);
         Ariticle ariticle = ars.FindById(ariticleId);
         AriticleViewModel avm = new AriticleViewModel(ariticle);
         avm.Title = ariticle.Title;
         avm.UGC = ariticle.UGC;
         avm.author = ariticle.User.NickName;
         avm.Createtime = ariticle.Createtime.ToString();
         Tree tree = new Tree();
         TreeNode treeNode = tree.SearchByAriticle(ariticle.Id);
         List<TreeNode> list = tree.GetTreeNodePath(treeNode);
         string result = "";
         for (int i = list.Count - 1; i >= 0; i--)
         {
             result = result + list[i].Title + "#";
         }
         string arrayList = "";
         List<AriticleVisibility> visibilityList = ars.GetAriticleVisibility(ariticle.Id);
         UserGroupService ugs = new UserGroupService();
         int count = ugs.FindAll().Count;
         if (0 == visibilityList.Count)
         {
             arrayList = JsonConvert.SerializeObject(avm) + "AriticleAndTreeNode" + result + "AriticleAndTreeNodeall";
         }
         else {
             VisibilityViewModel vvm = new VisibilityViewModel();
             List<VisibilityViewModel> vvlist = new List<VisibilityViewModel>();
             for (int i = 0; i < visibilityList.Count; i++)
             {
                 vvm = new VisibilityViewModel();
                 vvm.Id = visibilityList[i].Id;
                 vvm.UserGroupId = visibilityList[i].UserGroupId;
                 vvm.userGroupTitle = visibilityList[i].UserGroup.Title;
                 vvlist.Add(vvm);
             }
             string vlist = JsonConvert.SerializeObject(vvlist);
             arrayList = JsonConvert.SerializeObject(avm) + "AriticleAndTreeNode" + result + "AriticleAndTreeNode" + vlist;
         }
         return Content(arrayList);
     }
 }