using Microsoft.AspNetCore.Mvc; using Mini.Common; using Mini.Services.Bas; using Mini.Web.WebHelper; using System; using System.Collections.Generic; using System.Linq; namespace Mini.Web.Areas.Admin.Controllers { public class InnerUserRoleController : BaseController { ValidationErrors errors = new ValidationErrors(); private readonly IBasInnerUserRoleService _basInnerUserRoleService; public InnerUserRoleController(IBasInnerUserRoleService basInnerUserRoleService) { this._basInnerUserRoleService = basInnerUserRoleService; } #region 首页 [AuthorizeRedirect(Roles = InitRights.CONST_员工角色管理)] [Area("Admin")] public ActionResult Index() { //ToolBar ToolBar tool = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.员工角色管理, userRightId); tool.AllowButton(toolbtn); // tool.AllowButton("Other1"); tool.AddOtherButton("Other1", "分配角色", "icon-lookup", "SettingRole_Click", true); ViewBag.ToolBar = tool; Pager pager = new Pager() { page = 1, rows = 10 }; string tableId = "List"; Table tab = new Table(tableId); tab.isCheckbox = true; tab.AddHiddenHeadCol("pkid", "员工ID"); tab.AddHiddenHeadCol("roleIds", "角色ID"); tab.AddHeadCol("eID", "10%", "工号"); tab.AddHeadCol("uName", "10%", "名称"); tab.AddHeadCol("roleNames", "", "角色 "); tab.AddHeadRow(); ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "5,8,10,15"); return View(); } #endregion #region 列表 /// /// 按照条件获取数据 /// /// 分页信息 /// [AuthorizeRedirect(Roles = InitRights.CONST_员工角色管理)] [Area("Admin")] public JsonResult GetHtmlList(Pager pager, string columns, int? eId, string uName, string roleId) { var list = _basInnerUserRoleService.GetList(ref pager, eId, uName, roleId); Table table = new Table(columns, true); table.gridPager = pager; table.isCheckbox = true; foreach (var model in list) { table.AddHiddenCol(model.Uid); table.AddHiddenCol(model.RoleIds); table.AddCol(model.Eid); table.AddCol(model.UName); table.AddCol("text-align:left", "", "   " + model.RolesNames); table.AddRow(); } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json); } #endregion #region 角色分配 [AuthorizeToolBar(InitRights.CONST_员工角色管理, InitToolBar.CONST_Other1)] [Area("Admin")] public ActionResult SettingInnerUserRole() { ViewBag.isAdmin = Eid == 10000 ? "1" : "0"; return View(); } /// /// 保存权限分配 /// /// /// /// [AuthorizeToolBar(InitRights.CONST_员工角色管理, InitToolBar.CONST_Other1)] [Area("Admin")] public JsonResult Save(string roleIds, string pkids) { if (string.IsNullOrWhiteSpace(pkids)) return JsonHandler.ManageMessage("请选中员工!", false); _basInnerUserRoleService.Save(0, roleIds, pkids); return JsonHandler.ManageMessage(errors, true); } #endregion } }