using NFine.Application.SystemManage; using NFine.Code; using NFine.Domain.Entity.SystemManage; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Mvc; namespace NFine.Web.Controllers { [HandlerLogin] public class ClientsDataController : Controller { [HttpGet] [HandlerAjaxOnly] public ActionResult GetClientsDataJson() { var data = new { dataItems = this.GetDataItemList(), organize = this.GetOrganizeList(), role = this.GetRoleList(), duty = this.GetDutyList(), user = this.GetUserList(), authorizeMenu = this.GetMenuList(), authorizeButton = this.GetMenuButtonList(), }; return Content(data.ToJson()); } private object GetDataItemList() { var itemdata = new ItemsDetailApp().GetList(); Dictionary dictionaryItem = new Dictionary(); foreach (var item in new ItemsApp().GetList()) { var dataItemList = itemdata.FindAll(t => t.F_ItemId.Equals(item.F_Id)); Dictionary dictionaryItemList = new Dictionary(); foreach (var itemList in dataItemList) { dictionaryItemList.Add(itemList.F_ItemCode, itemList.F_ItemName); } dictionaryItem.Add(item.F_EnCode, dictionaryItemList); } return dictionaryItem; } private object GetUserList() { UserApp userApp = new UserApp(); var data = userApp.GetList(); Dictionary dictionary = new Dictionary(); foreach (UserEntity item in data) { var fieldItem = new { realname = item.F_RealName, nickname = item.F_NickName }; dictionary.Add(item.F_Id,fieldItem); } return dictionary; } private object GetOrganizeList() { OrganizeApp organizeApp = new OrganizeApp(); var data = organizeApp.GetList(); Dictionary dictionary = new Dictionary(); foreach (OrganizeEntity item in data) { var fieldItem = new { encode = item.F_EnCode, fullname = item.F_FullName }; dictionary.Add(item.F_Id, fieldItem); } return dictionary; } private object GetRoleList() { RoleApp roleApp = new RoleApp(); var data = roleApp.GetList(); Dictionary dictionary = new Dictionary(); foreach (RoleEntity item in data) { var fieldItem = new { encode = item.F_EnCode, fullname = item.F_FullName }; dictionary.Add(item.F_Id, fieldItem); } return dictionary; } private object GetDutyList() { DutyApp dutyApp = new DutyApp(); var data = dutyApp.GetList(); Dictionary dictionary = new Dictionary(); foreach (RoleEntity item in data) { var fieldItem = new { encode = item.F_EnCode, fullname = item.F_FullName }; dictionary.Add(item.F_Id, fieldItem); } return dictionary; } private object GetMenuList() { var roleId = OperatorProvider.Provider.GetCurrent().RoleId; return ToMenuJson(new RoleAuthorizeApp().GetMenuList(roleId), "0"); } private string ToMenuJson(List data, string parentId) { StringBuilder sbJson = new StringBuilder(); sbJson.Append("["); List entitys = data.FindAll(t => t.F_ParentId == parentId); if (entitys.Count > 0) { foreach (var item in entitys) { string strJson = item.ToJson(); strJson = strJson.Insert(strJson.Length - 1, ",\"ChildNodes\":" + ToMenuJson(data, item.F_Id) + ""); sbJson.Append(strJson + ","); } sbJson = sbJson.Remove(sbJson.Length - 1, 1); } sbJson.Append("]"); return sbJson.ToString(); } private object GetMenuButtonList() { var roleId = OperatorProvider.Provider.GetCurrent().RoleId; var data = new RoleAuthorizeApp().GetButtonList(roleId); var dataModuleId = data.Distinct(new ExtList("F_ModuleId")); Dictionary dictionary = new Dictionary(); foreach (ModuleButtonEntity item in dataModuleId) { var buttonList = data.Where(t => t.F_ModuleId.Equals(item.F_ModuleId)); dictionary.Add(item.F_ModuleId, buttonList); } return dictionary; } } }