using Lottomat.Application.Busines.AuthorizeManage;
using Lottomat.Application.Busines.BaseManage;
using Lottomat.Application.Code;
using Lottomat.Application.Entity.AuthorizeManage;
using Lottomat.Application.Entity.BaseManage;
using Lottomat.Util;
using Lottomat.Util.Extension;
using Lottomat.Util.WebControl;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.Mvc;
using Lottomat.Application.Code.Authorize;
namespace Lottomat.Application.Admin.Areas.AuthorizeManage.Controllers
{
///
/// 版 本
/// Copyright (c) 2016-2017
/// 创建人:赵轶
/// 日 期:2015.11.2 2:35
/// 描 述:用户权限
///
public class PermissionUserController : MvcControllerBase
{
private OrganizeBLL organizeBLL = new OrganizeBLL();
private DepartmentBLL departmentBLL = new DepartmentBLL();
private RoleBLL roleBLL = new RoleBLL();
private UserBLL userBLL = new UserBLL();
private ModuleBLL moduleBLL = new ModuleBLL();
private ModuleButtonBLL moduleButtonBLL = new ModuleButtonBLL();
private ModuleColumnBLL moduleColumnBLL = new ModuleColumnBLL();
private PermissionBLL permissionBLL = new PermissionBLL();
#region 视图功能
///
/// 用户权限
///
///
[HttpGet]
[HandlerAuthorize(PermissionMode.Enforce)]
public ActionResult AllotAuthorize()
{
return View();
}
#endregion
#region 获取数据
///
/// 系统功能列表
///
/// 用户Id
///
[HttpGet]
public ActionResult ModuleTreeJson(string userId)
{
var existModule = permissionBLL.GetModuleList(userId);
var data = moduleBLL.GetList();
var treeList = new List();
foreach (ModuleEntity item in data)
{
TreeEntity tree = new TreeEntity();
bool hasChildren = data.Count(t => t.ParentId == item.ModuleId) == 0 ? false : true;
tree.id = item.ModuleId;
tree.text = item.FullName;
tree.value = item.ModuleId;
tree.title = "";
tree.checkstate = existModule.Count(t => t.ItemId == item.ModuleId);
tree.showcheck = true;
tree.isexpand = true;
tree.complete = true;
tree.hasChildren = hasChildren;
tree.parentId = item.ParentId;
tree.img = item.Icon;
treeList.Add(tree);
}
return Content(treeList.TreeToJson());
}
///
/// 系统按钮列表
///
/// 用户Id
///
[HttpGet]
public ActionResult ModuleButtonTreeJson(string userId)
{
var existModuleButton = permissionBLL.GetModuleButtonList(userId);
var moduleData = moduleBLL.GetList();
var moduleButtonData = moduleButtonBLL.GetList();
var treeList = new List();
foreach (ModuleEntity item in moduleData)
{
TreeEntity tree = new TreeEntity();
tree.id = item.ModuleId;
tree.text = item.FullName;
tree.value = item.ModuleId;
tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleId);
tree.showcheck = true;
tree.isexpand = true;
tree.complete = true;
tree.hasChildren = true;
tree.parentId = item.ParentId;
tree.img = item.Icon;
treeList.Add(tree);
}
foreach (ModuleButtonEntity item in moduleButtonData)
{
TreeEntity tree = new TreeEntity();
bool hasChildren = moduleButtonData.Count(t => t.ParentId == item.ModuleButtonId) == 0 ? false : true;
tree.id = item.ModuleButtonId;
tree.text = item.FullName;
tree.value = item.ModuleButtonId;
if (item.ParentId == "0")
{
tree.parentId = item.ModuleId;
}
else
{
tree.parentId = item.ParentId;
}
tree.checkstate = existModuleButton.Count(t => t.ItemId == item.ModuleButtonId);
tree.showcheck = true;
tree.isexpand = true;
tree.complete = true;
tree.img = "fa fa-wrench " + item.ModuleId;
tree.hasChildren = hasChildren;
treeList.Add(tree);
}
return Content(treeList.TreeToJson());
}
///
/// 系统视图列表
///
/// 用户Id
///
[HttpGet]
public ActionResult ModuleColumnTreeJson(string userId)
{
var existModuleColumn = permissionBLL.GetModuleColumnList(userId);
var moduleData = moduleBLL.GetList();
var moduleColumnData = moduleColumnBLL.GetList();
var treeList = new List();
foreach (ModuleEntity item in moduleData)
{
TreeEntity tree = new TreeEntity();
tree.id = item.ModuleId;
tree.text = item.FullName;
tree.value = item.ModuleId;
tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleId);
tree.showcheck = true;
tree.isexpand = true;
tree.complete = true;
tree.hasChildren = true;
tree.parentId = item.ParentId;
tree.img = item.Icon;
treeList.Add(tree);
}
foreach (ModuleColumnEntity item in moduleColumnData)
{
TreeEntity tree = new TreeEntity();
bool hasChildren = moduleColumnData.Count(t => t.ParentId == item.ModuleColumnId) == 0 ? false : true;
tree.id = item.ModuleColumnId;
tree.text = item.FullName;
tree.value = item.ModuleColumnId;
if (item.ParentId == "0")
{
tree.parentId = item.ModuleId;
}
else
{
tree.parentId = item.ParentId;
}
tree.checkstate = existModuleColumn.Count(t => t.ItemId == item.ModuleColumnId);
tree.showcheck = true;
tree.isexpand = true;
tree.complete = true;
tree.img = "fa fa-filter " + item.ModuleId;
tree.hasChildren = hasChildren;
treeList.Add(tree);
}
return Content(treeList.TreeToJson());
}
///
/// 数据权限列表
///
/// 用户Id
///
[HttpGet]
public ActionResult OrganizeTreeJson(string userId)
{
var existAuthorizeData = permissionBLL.GetAuthorizeDataList(userId);
var organizedata = organizeBLL.GetList();
var departmentdata = departmentBLL.GetList();
var treeList = new List();
foreach (OrganizeEntity item in organizedata)
{
TreeEntity tree = new TreeEntity();
bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true;
if (hasChildren == false)
{
hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true;
if (hasChildren == false)
{
continue;
}
}
tree.id = item.OrganizeId;
tree.text = item.FullName;
tree.value = item.OrganizeId;
tree.parentId = item.ParentId;
if (item.ParentId == "0")
{
tree.img = "fa fa-sitemap";
}
else
{
tree.img = "fa fa-home";
}
tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.OrganizeId);
tree.showcheck = true;
tree.isexpand = true;
tree.complete = true;
tree.hasChildren = hasChildren;
treeList.Add(tree);
}
foreach (DepartmentEntity item in departmentdata)
{
TreeEntity tree = new TreeEntity();
bool hasChildren = departmentdata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true;
tree.id = item.DepartmentId;
tree.text = item.FullName;
tree.value = item.DepartmentId;
if (item.ParentId == "0")
{
tree.parentId = item.OrganizeId;
}
else
{
tree.parentId = item.ParentId;
}
tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.DepartmentId);
tree.showcheck = true;
tree.isexpand = true;
tree.complete = true;
tree.img = "fa fa-umbrella";
tree.hasChildren = hasChildren;
treeList.Add(tree);
}
int authorizeType = -1;
if (existAuthorizeData.ToList().Count > 0)
{
authorizeType = existAuthorizeData.ToList()[0].AuthorizeType.ToInt();
}
var JsonData = new
{
authorizeType = authorizeType,
authorizeData = existAuthorizeData,
treeJson = treeList.TreeToJson(),
};
return Content(JsonData.ToJson());
}
#endregion
#region 提交数据
///
/// 保存用户授权
///
/// 用户Id
/// 功能Id
/// 按钮Id
/// 视图Id
/// 数据权限
///
[HttpPost]
[ValidateAntiForgeryToken]
[AjaxOnly]
public ActionResult SaveAuthorize(string userId, string moduleIds, string moduleButtonIds, string moduleColumnIds, string authorizeDataJson)
{
permissionBLL.SaveAuthorize(AuthorizeTypeEnum.User, userId, moduleIds, moduleButtonIds, moduleColumnIds, authorizeDataJson);
return Success("保存成功。");
}
#endregion
}
}