public static void TestTree() { using (var db = new RRDLEntities()) { TreeNode rootNode = new TreeNode(null, "测试Root"); rootNode.Title = "测试Root"; Tree tree = TreeSet.CreateNewTree(rootNode, "R2Team知识"); TreeNode level1 = new TreeNode(rootNode.Id,"level1"); //TreeNode treeNode=tree.GetTreeNodeById(tree.RootNode.Id); // level1.ParentId = treeNode; tree.AddTreeNode(level1); TreeNode level2 = new TreeNode(level1.Id,"level2"); tree.AddTreeNode(level2); TreeNode level3 = new TreeNode(level2.Id,"level3"); tree.AddTreeNode(level3); TreeNode level4 = new TreeNode(level2.Id, "level3-1"); tree.AddTreeNode(level4); //Tree tree = new Tree("R2Team知识"); tree.GetTreeNodePath(level4); } }
//public string getMemberById(string userId) { // UserService userservice = new UserService(); // User user = userservice.FindById(userId); // MemberViewModel mvm = new MemberViewModel(user); // UserGroupService ugs = new UserGroupService(); // List<UserGroup> list = ugs.FindAll(); // string memberResult = JsonConvert.SerializeObject(mvm); // 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 result = JsonConvert.SerializeObject(ugvlist); // return memberResult+"MemberAndGroupList"+result; //} public string getMemberById(string userId) { using (RRDLEntities db = new RRDLEntities()) { UserService userservice = new UserService(); User user = userservice.FindById(userId); MemberViewModel mvm = new MemberViewModel(user); int approvedcount = 0; int allcount = 0; AriticleService ariticleService = new AriticleService(); Expression<Func<Ariticle, bool>> condition = a => a.Approve.ApproveStatus == EnumAriticleApproveStatus.Approved && a.UserId == user.Id; approvedcount = ariticleService.GetAriticleCount(condition); condition = a => a.UserId == user.Id; allcount = ariticleService.GetAriticleCount(condition); mvm.approvedArticleCount = approvedcount; mvm.allArticleCount = allcount; UserGroupService ugs = new UserGroupService(); List<UserGroup> list = ugs.FindAll(); string memberResult = JsonConvert.SerializeObject(mvm); 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 result = JsonConvert.SerializeObject(ugvlist); return memberResult + "MemberAndGroupList" + result; } }
/// <summary> /// 检索功能入口函数 /// </summary> /// <param name="_method">方法名称</param> /// <param name="condition">查询条件</param> /// <returns></returns> public string GetArcticle(string keyword, int numOnePage, int pageIndex,int leve,string userId) { using (RRDLEntities db = new RRDLEntities()) { string newkey = System.Web.HttpUtility.UrlDecode(keyword).ToLower().Trim(); AriticleService ars = new AriticleService(db); List<Ariticle> arlists = new List<Ariticle>(); arlists = ars.SearchAriticles(newkey, numOnePage, pageIndex); int n = ars.SearchAllAriticlesCount(newkey); switch (leve) { //游客 case -1: arlists = isVisibilityUser(ars,arlists,null); break; //普通用户 case 1: arlists = isVisibilityUser(ars, arlists, userId); break; } List<AriticleViewModel> avmlist = new List<AriticleViewModel>(); avmlist = SimplifyAriticle(arlists); string result = JsonConvert.SerializeObject(avmlist); result = result + "ContentAndCount" + n; return result; } }
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 Delete(string userGroupId) { using (RRDLEntities db = new RRDLEntities()) { UserGroupService ugs = new UserGroupService(db); ugs.Drop(Int32.Parse(userGroupId)); db.SaveChanges(); return null; } }
/// 以下是select框选择时的方法 public ActionResult SelectSearch(int numOnePage, int pageIndex, string keyword, int ariticleApproveStatus) { using (RRDLEntities db = new RRDLEntities()) { keyword = System.Web.HttpUtility.UrlDecode(keyword); AriticleService ariticleService = new AriticleService(db); List<Ariticle> list = new List<Ariticle>(); list = ariticleService.KnowledgeManageSelectSearchAriticles(keyword, ariticleApproveStatus, numOnePage, pageIndex, db); int count = ariticleService.KnowledgeManageSelectSearchAriticlesCount(keyword, ariticleApproveStatus, db); List<AriticleViewModel> Viewlist = SimplifyAriticle(list); string result = JsonConvert.SerializeObject(Viewlist); result = result + "ContentAndCount" + count; return Content(result); } }
public ActionResult TextAndSelectSearch(string userId, string keyword, int ariticleApproveStatus, int numOnePage, int pageIndex) { //知识分类 知识标题 知识标签 审核状态 using (RRDLEntities db = new RRDLEntities()) { AriticleService articleService = new AriticleService(db); List<Ariticle> list = new List<Ariticle>(); list = articleService.PCSelectSearchAriticles(userId, keyword, ariticleApproveStatus, numOnePage, pageIndex, db); List<AriticleViewModel> Viewlist = SimplifyAriticle(list); int count = articleService.PCSelectSearchAriticlesCount(userId, keyword, ariticleApproveStatus, db); string result = JsonConvert.SerializeObject(Viewlist); result = result + "ContentAndCount" + count; return Content(result); } }
public string UserGroupIsEmpty(string userGroupId) { using (RRDLEntities db = new RRDLEntities()) { UserGroupService ugs = new UserGroupService(db); UserGroup ug = ugs.FindById(Int32.Parse(userGroupId)); int count = ug.Users.Count; if (count == 0) { return "true"; } else { return "false"; } } }
public ActionResult TextSearch(string userId, string keyword, int numOnePage, int pageIndex) { //知识分类 知识标题 知识标签 using (RRDLEntities db = new RRDLEntities()) { keyword = System.Web.HttpUtility.UrlDecode(keyword); AriticleService articleService = new AriticleService(db); List<Ariticle> list = new List<Ariticle>(); list = articleService.PCSearchAriticles(userId, keyword, numOnePage, pageIndex, db); int count = articleService.PCSearchAriticlesCount(userId, keyword, db); List<AriticleViewModel> Viewlist = SimplifyAriticle(list); string result = JsonConvert.SerializeObject(Viewlist); result = result + "ContentAndCount" + count; return Content(result); } }
//// NodeId: id, NodeInfo: nodeInfo, XmlUrl: temp.xmlUrl public ActionResult OperateTreeNode(string modeType, string _modeType, string nodeId, string nodeInfo, string xmlUrl) { using (RRDLEntities db = new RRDLEntities()) { Tree tree = new Tree(); TreeNode treeNode = null; switch (modeType) { case "rename": string id = nodeId; string name = nodeInfo; treeNode = tree.GetTreeNodeById(Int32.Parse(id)); treeNode.Title = name; tree.UpdateTreeNode(treeNode); returnStr = "ok&" + treeNode.ParentId; break; case "delete": returnStr = DeleteNode(_modeType, nodeId, xmlUrl); break; case "insert": //List<NodeInfo> nodeList = this.GetListFromJson(nodeInfo); //returnStr = this.InserNode(_modeType, nodeId, xmlUrl, nodeList); //bool flag = true; Tree tree2 = new Tree(db); List<TreeNode> list = tree2.GetTreeNodeChild(Int32.Parse(nodeId)); //for (int i = 0; i < list.Count;i++ ) //{ // if(list[i].Ariticle != null){ // flag = false; // } //} //if (flag) //{ treeNode = new TreeNode(Int32.Parse(nodeId), "新建节点"); tree.AddTreeNode(treeNode); returnStr = "ok"; //} //else { // returnStr = "该节点下存在文章,不能添加文件夹!"; //} break; } return Content(returnStr); } }
//参数 用户名 每页条数 页码 public ActionResult ShowOwnKnowledgeItem(string userId, int numOnePage, int pageIndex) { using (RRDLEntities db = new RRDLEntities()) { AriticleService articleService = new AriticleService(); List<Ariticle> list = new List<Ariticle>(); list = articleService.FindAriticlesByUser(userId, numOnePage, pageIndex, db); int n = list.Count; AriticleService articleService1 = new AriticleService(); int totalCount = articleService1.GetAriticleCount(userId); List<AriticleViewModel> ariticleList = new List<AriticleViewModel>(); for (int i = 0; i < n; i++) { AriticleViewModel temp = new AriticleViewModel(list[i]); temp.ApproveStatus = list[i].Approve.ApproveStatus; temp.Id = list[i].Id; string time1 = list[i].Createtime.ToLongDateString(); string time2 = list[i].Createtime.ToLongTimeString(); temp.Createtime = time1 + " " + time2; temp.Title = list[i].Title; if (list[i].UGC.Length > 300) { temp.UGC = list[i].UGC.Substring(0, 300); } else { temp.UGC = list[i].UGC; } // temp.Tags = list[i].Tags; temp.Title = list[i].Title; temp.User = null; ariticleList.Add(temp); } string length = (ariticleList.Count).ToString(); string result = JsonConvert.SerializeObject(ariticleList); result = result + "ContentAndCount" + totalCount; return Content(result); } }
//判断选择节点是否正确 public string isAdd(string treeNode) { using (RRDLEntities db = new RRDLEntities()) { Tree tree = new Tree(db); List<TreeNode> list = tree.GetTreeNodeChild(Int32.Parse(treeNode)); string flag = ""; if (list.Count > 0) { if (list[0].Ariticle != null) { flag = "true"; } } else { flag = "true"; } return flag; } }
public ActionResult GetTreeByRootIdForTreeManage(string nodeId, string treeName) { using (RRDLEntities db = new RRDLEntities()) { Tree tree = new Tree(db); TreeNode rootNode = tree.GetRootNode(treeName); string result = ""; if (nodeId != "") { int rootId = Int32.Parse(nodeId); List<TreeNode> list = tree.GetTreeNodeChild(rootId); TreeViewModel tvm = new TreeViewModel(); List<TreeViewModel> tlist = new List<TreeViewModel>(); for (int i = 0; i < list.Count; i++) { if (list[i].Ariticle == null) { tvm = new TreeViewModel(); tvm.Deepth = list[i].Deepth; tvm.Id = list[i].Id; tvm.IsLeaf = false; tvm.ParentId = list[i].ParentId; tvm.Title = list[i].Title; tlist.Add(tvm); } } result = JsonConvert.SerializeObject(tlist); } else { result = "[{\"Ariticle\":\"null\",\"Id\":\"" + rootNode.Id + "\",\"Title\":\"" + rootNode.Title + "\",\"Deepth\":\"" + rootNode.Deepth + "\",\"ParentId\":\"null\",\"IsLeaf\":\"" + rootNode.IsLeaf + "\"}]"; } // List<TreeNode> return Content(result); } }
/// <summary> /// 传入组id,返回小组信息 ZHAOs 2014年5月23日12:08:56 /// </summary> /// <param name="groupId"></param> /// <returns></returns> public ActionResult GetGroupByGroupId(int groupId) { RRDLEntities re = new RRDLEntities(); UserGroupService ugs = new UserGroupService(re); re.Configuration.ProxyCreationEnabled = false; UserGroup ug = ugs.FindById(groupId); return Json(ug); }
public ActionResult KnowledgeAudit(int numOnePage, int pageIndex, string userGroupId) { using (RRDLEntities db = new RRDLEntities()) { AriticleService ariticleService = new AriticleService(); List<Ariticle> list = new List<Ariticle>(); int count = 0; if (userGroupId == "2") { list = ariticleService.FindAriticlesByApproveStatus( EnumAriticleApproveStatus.UnApproved, numOnePage, pageIndex, db); count = ariticleService.GetAriticleCount(EnumAriticleApproveStatus.UnApproved); } else { int id = Int32.Parse(userGroupId); Expression<Func<Ariticle, bool>> condition = a => a.User.ContentGroupId == id && a.Approve.ApproveStatus == EnumAriticleApproveStatus.UnApproved; list = ariticleService.FindAriticles(condition, numOnePage, pageIndex, db); count = ariticleService.GetAriticleCount(condition); } List<AriticleViewModel> Viewlist = SimplifyAriticle(list); string result = JsonConvert.SerializeObject(Viewlist); result = result + "ContentAndCount" + count; return Content(result); } }
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); } }
public ActionResult KnowledgeManage(int numOnePage, int pageIndex, string state, string userGroupId) { using (RRDLEntities db = new RRDLEntities()) { AriticleService ariticleService = new AriticleService(); List<Ariticle> list = new List<Ariticle>(); string s = state; int count = 0; int id = 0; id = Int32.Parse(userGroupId); switch (state) { case null: case "all": if (userGroupId == "2") { Expression<Func<Ariticle, bool>> condition = a => a.Approve.ApproveStatus == EnumAriticleApproveStatus.Approved || a.Approve.ApproveStatus == EnumAriticleApproveStatus.FailedApprove; list = ariticleService.FindAriticlesManage(condition, numOnePage, pageIndex, db); count = ariticleService.GetAriticleCount(condition); break; } else { Expression<Func<Ariticle, bool>> condition = a => (a.Approve.ApproveStatus == EnumAriticleApproveStatus.Approved || a.Approve.ApproveStatus == EnumAriticleApproveStatus.FailedApprove) && a.User.ContentGroupId == id; list = ariticleService.FindAriticlesManage(condition, numOnePage, pageIndex, db); count = ariticleService.GetAriticleCount(condition); break; } case "AuditPass": if (userGroupId == "2") { //list = ariticleService.FindAriticlesByApproveStatus(EnumAriticleApproveStatus.Approved, //numOnePage, pageIndex, db); //count = ariticleService.GetAriticleCount(EnumAriticleApproveStatus.Approved); Expression<Func<Ariticle, bool>> condition = a => a.Approve.ApproveStatus == EnumAriticleApproveStatus.Approved; list = ariticleService.FindAriticlesManage(condition, numOnePage, pageIndex, db); count = ariticleService.GetAriticleCount(condition); break; } else { Expression<Func<Ariticle, bool>> condition = a => a.Approve.ApproveStatus == EnumAriticleApproveStatus.Approved && a.User.ContentGroupId == id; list = ariticleService.FindAriticlesManage(condition, numOnePage, pageIndex, db); count = ariticleService.GetAriticleCount(condition); break; } case "AuditUnqualified": if (userGroupId == "2") { //list = ariticleService.FindAriticlesByApproveStatus( // EnumAriticleApproveStatus.FailedApprove, numOnePage, pageIndex, db); //count = ariticleService.GetAriticleCount(EnumAriticleApproveStatus.FailedApprove); Expression<Func<Ariticle, bool>> condition = a => a.Approve.ApproveStatus == EnumAriticleApproveStatus.FailedApprove; list = ariticleService.FindAriticlesManage(condition, numOnePage, pageIndex, db); count = ariticleService.GetAriticleCount(condition); break; } else { Expression<Func<Ariticle, bool>> condition = a => a.Approve.ApproveStatus == EnumAriticleApproveStatus.FailedApprove && a.User.ContentGroupId == id; list = ariticleService.FindAriticlesManage(condition, numOnePage, pageIndex, db); count = ariticleService.GetAriticleCount(condition); break; } } List<AriticleViewModel> Viewlist = SimplifyAriticle(list); string result = JsonConvert.SerializeObject(Viewlist); result = result + "ContentAndCount" + count; return Content(result); } }
/// <summary> /// 后台返回:所有小组名称和小组ID /// </summary> /// <returns></returns> public JsonResult GetAllGroups() { RRDLEntities rr = new RRDLEntities(); UserGroupService ugs = new UserGroupService(rr); rr.Configuration.ProxyCreationEnabled = false; List<UserGroup> list = ugs.FindAll(); List<UserGroup> newList = new List<UserGroup>();//去除了游客和超级管理员之后的UserGroup foreach (var l in list) { if (l.Id != 1 && l.Id != 2) { newList.Add(l); } } return Json(newList); }
public string GetUserById(string userId) { using (RRDLEntities db = new RRDLEntities()) { UserService us = new UserService(); User user = us.FindById(userId); UserViewModel uvm = new UserViewModel(); uvm.NickName = user.NickName; uvm.RealName = user.RealName; uvm.RegisterName = user.RegisterName; uvm.Category = getAuthorityCategory(user.AuthorityCategory); int ugid = (int)user.ContentGroupId; UserGroupService ugs = new UserGroupService(); UserGroup ug = ugs.FindById(ugid); uvm.UserGroup = ug.Title; uvm.CreateTime = user.Createtime.ToString(); int approvedcount = 0; int allcount = 0; AriticleService ariticleService = new AriticleService(); Expression<Func<Ariticle, bool>> condition = a => a.Approve.ApproveStatus == EnumAriticleApproveStatus.Approved && a.UserId == user.Id; approvedcount = ariticleService.GetAriticleCount(condition); condition = a => a.UserId == user.Id; allcount = ariticleService.GetAriticleCount(condition); uvm.approvedArticleCount = approvedcount; uvm.allArticleCount = allcount; string result = JsonConvert.SerializeObject(uvm); return result; } }
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; } }
public static void TestAddAriticleApprove() { AriticleApprove approve = new AriticleApprove { //AriticleId="1" }; RRDLEntities db = new RRDLEntities(); db.AriticleApproves.Add(approve); db.SaveChanges(); }
/// <summary> /// 后台返回:所有成员名称和成员ID /// </summary> /// <returns></returns> public JsonResult GetAllMembers() { RRDLEntities rr = new RRDLEntities(); UserService us = new UserService(rr); rr.Configuration.ProxyCreationEnabled = false; List<User> list = us.FindAll(); return Json(list); }
/// <summary> /// 通过TreeNodeId获取Ariticle /// </summary> /// <param name="_modeType"></param> /// <param name="_nodeId"></param> /// <param name="_xmlUrl"></param> /// <param name="_nodeInfo"></param> /// <returns></returns> public ActionResult GetAriticleByTreeNodeId(string treeNodeId,string userId) { using (RRDLEntities db = new RRDLEntities()) { Tree tree = new Tree(db); Ariticle ariticle = tree.GetTreeNodeById(Int32.Parse(treeNodeId)).Ariticle; PraiseRepository pr = new PraiseRepository(); //如果是叶子节点,传递知识内容到前台 if (ariticle != null) { AriticleViewModel avm = new AriticleViewModel(ariticle); UserService us = new UserService(); User author = us.FindById(ariticle.UserId); avm.author = author.NickName; string time1 = ariticle.Createtime.ToLongDateString(); string time2 = ariticle.Createtime.ToLongTimeString(); avm.Createtime = time1 + " " + time2; //avm.PraiseCount = pr.FindByAriticleID(ariticle.Id).PraiseCount; avm.Id = ariticle.Id; AriticleService ars = new AriticleService(); string isShow = ""; if(userId == "vistor"){ userId = null; } if (ars.GetAriticleVisibilityByUser(ariticle.Id, userId)) { bool falg = ars.GetAriticleVisibilityByUser(ariticle.Id, userId); isShow = "true"; } else { bool falg = ars.GetAriticleVisibilityByUser(ariticle.Id, userId); isShow = "false"; } User user = us.FindById(userId); if(user!=null && user.ContentGroupId == 2){ isShow = "true"; } string result = JsonConvert.SerializeObject(avm); result = result + "ThisAriticleIsShowForThisUser" + isShow; return Content(result); } else { return Content("NotLeaf"); } } }
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"; } }
//根据传进来的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 static void TestAriticleInvisibility() { AriticleVisibility invis = new AriticleVisibility(); invis.AriticleId = "1"; UserGroupRepository repository = new UserGroupRepository(); UserGroup group=repository.FindByGroupTitle("R2Team"); invis.UserGroupId = group.Id; RRDLEntities db = new RRDLEntities(); db.AriticleVisibilitys.Add(invis); db.SaveChanges(); AriticleVisibilityRepository rep = new AriticleVisibilityRepository(); //AriticleInvisibility arcInvis=rep.FindByAriticle("1"); // db.AriticleInvisibilitys }