| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using CallCenter.Utility;
- using CallCenterApi.Interface.Controllers.Base;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CallCenterApi.Interface.Controllers.knowledge
- {
- public class KnowledgeClassController : BaseController
- {
- // 获取知识库分类列表
- public ActionResult GetAllList()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- DataTable dt = new DataTable();
- string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
- string sql = "";
- dt = new BLL.T_RepositoryCategory().GetList(sql).Tables[0];
- res = Success("加载成功", dt);
- return res;
- }
- // 获取知识库分类列表
- public ActionResult GetList()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- DataTable dt = new DataTable();
- string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
- string sql = "";
- if (pid.Trim() != "")
- {
- sql += " and F_ParentId=" + pid.Trim();
- }
- else
- sql += " and F_ParentId=0";
- dt = new BLL.T_RepositoryCategory().GetList(" 1=1 " + sql).Tables[0];
- List<Model.TreeModel> modelList = BindTree(dt, "0");
- if (modelList.Count > 0)
- {
- res = Success("加载成功", modelList);
- }
- else
- res = Error("加载失败");
- return res;
- }
- //tree 树形知识库分类
- private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
- {
- DataTable tab2 = new DataTable();
- if (tab != null && tab.Rows.Count > 0)
- {
- List<Model.T_RepositoryCategory> categorylist = new BLL.T_RepositoryCategory().DataTableToList(tab);
- List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
- for (int i = 0; i < categorylist.Count; i++)
- {
- Model.TreeModel model = new Model.TreeModel();
- string currentID = categorylist[i].F_CategoryId.ToString();//当前功能ID
- model.id = currentID;
- model.IconCls = "";//图标
- model.text = categorylist[i].F_CategoryName;
- tab2 = new BLL.T_RepositoryCategory().GetList(" F_ParentId=" + currentID + " ").Tables[0];
- if (tab2 != null && tab2.Rows.Count > 0)
- {
- model.children = BindTree(tab2, currentID);
- }
- modelList.Add(model);
- }
- return modelList;
- }
- else
- {
- return null;
- }
- }
- //获取知识库分类
- public ActionResult GetClass(string categoryid)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (categoryid != null && categoryid.Trim() != "")
- {
- BLL.T_RepositoryCategory dBLL = new BLL.T_RepositoryCategory();
- Model.T_RepositoryCategory dModel = dBLL.GetModel(int.Parse(categoryid.Trim()));
- if (dModel != null)
- {
- res = Success("获取知识库分类信息成功", dModel);
- }
- else
- {
- res = Error("获取知识库分类信息失败");
- }
- }
- else
- {
- res = Error("获取参数失败");
- }
- return res;
- }
- //[Authority]
- //添加知识库分类
- public ActionResult AddClass(string cname, string pid)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- Model.T_RepositoryCategory dModel = new Model.T_RepositoryCategory();
- if (pid != "")
- {
- dModel.F_ParentId = int.Parse(pid.Trim());
- }
- else
- dModel.F_ParentId = 0;
-
- dModel.F_CategoryName = cname.Trim();
- dModel.F_CreateOn = DateTime.Now;
- dModel.F_CreateBy = int.Parse(User.UserData["F_UserID"]);
-
- int b = new BLL.T_RepositoryCategory().Add(dModel);
- if (b > 0)
- {
- res = Success("添加成功");
- }
- else
- {
- res = Success("添加失败");
- }
- }
- return res;
- }
- //[Authority]
- //编辑知识库分类
- public ActionResult EditClass(string cid, string cname, string pid)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- if (cid != null && cid.Trim() != "")
- {
- BLL.T_RepositoryCategory dBLL = new BLL.T_RepositoryCategory();
- Model.T_RepositoryCategory dModel = dBLL.GetModel(int.Parse(cid.Trim()));
- if (dModel != null)
- {
- if (pid.Trim() != "")
- {
- dModel.F_ParentId = int.Parse(pid.Trim());
- }
-
- if (cname.Trim() != "")
- {
- dModel.F_CategoryName = cname.Trim();
- }
- bool b = dBLL.Update(dModel);
- if (b)
- {
- res = Success("编辑成功");
- }
- else
- {
- res = Success("编辑失败");
- }
- }
- else
- res = Error("获取信息失败");
- }
- else
- {
- res = Error("请选择要编辑的知识库分类");
- }
- }
- return res;
- }
- //[Authority]
- //删除知识库分类
- public ActionResult DelClass(string ids)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
-
- if (ids != null && ids.Length > 0)
- {
- DataTable dt = new BLL.T_RepositoryInformation().GetList("F_CategoryId=" + Convert.ToInt32(ids)).Tables[0];
- string rid = string.Empty;
- if (dt.Rows.Count > 0)
- {
- //先删除知识库信息再删除知识库分类
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- rid = dt.Rows[i]["F_RepositoryId"].ToString();
- if (!string.IsNullOrEmpty(rid))
- {
- new BLL.T_RepositoryInformation().Delete(Convert.ToInt32(rid));
- }
- }
- }
- bool r = new BLL.T_RepositoryCategory().Delete(Convert.ToInt32(ids));
- if (r)
- res = Success("删除成功");
- else
- {
- res = Error("删除失败");
- }
- }
- else
- {
- res = Error("获取参数失败");
- }
- return res;
- }
- }
- }
|