Mini.Crm/Mini.Web/Areas/Admin/Controllers/RoleController.cs

211 lines
7.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using Mini.Common;
using Mini.Model.Entity;
using Mini.Model.ViewModel;
using Mini.Services.Bas;
using Mini.Services.ww;
using Mini.Web.WebHelper;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Mini.Web.Areas.Admin.Controllers
{
public class RoleController : BaseController
{
ValidationErrors errors = new ValidationErrors();
private readonly IBasRoleService _basRoleServide;
private readonly Iww_hhuser_Service _wwhhuser_service;
public RoleController(IBasRoleService basRoleServide, Iww_hhuser_Service wwhhuser_service)
{
this._basRoleServide = basRoleServide;
this._wwhhuser_service = wwhhuser_service;
}
#region
[Area("Admin")]
[AuthorizeRedirect(Roles = InitRights.CONST_角色管理)]
public ActionResult Index()
{
//ToolBar
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
// tool.AllowButton("Create", "Edit", "Details", "Other1", "Delete");
tool.AddOtherButton("Other1", "更新顺序", "icon-reload", "UpdateSort_Click", true);
tool.AddOtherButton("Other2", "绑定企微部门", "icon-flag", "BindQW_Click", true);
ViewBag.ToolBar = tool;
//DataGrid
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("ROLEID", "10%", "角色ID");
tab.AddHeadCol("RNAME", "", "角色名称 ");
tab.AddHeadCol("CODE", "", "编码");
tab.AddHeadCol("SORTID", "10%", "排序");
tab.AddHeadCol("CREATEUSER", "10%", "创建人");
tab.AddHeadCol("CTIME", "10%", "创建时间");
tab.AddHeadCol("UPDATEUSER", "10%", "修改人");
tab.AddHeadCol("UTIME", "10%", "修改时间");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
return View();
}
[Area("Admin")]
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Other2)]
public ActionResult BindQW(int roleid)
{
ViewBag.roleid = roleid;
return View(_basRoleServide.Get(roleid));
}
public JsonResult BindQWRole(List<Ww_Dept_Corp> list, string roleid)
{
if (string.IsNullOrEmpty(roleid))
{
errors.Add("参数不对!");
return JsonHandler.ManageMessage(errors, true);
}
bool result= _wwhhuser_service.SaveRoleDeptID(ref errors, list, Convert.ToInt32(roleid));
return JsonHandler.UpdateMessage(errors, result);
}
public JsonResult GetQWDept(int roleid)
{
var list = _wwhhuser_service.GetDept(roleid);
return Json(list);
}
/// <summary>
/// 获取全部数据列表
/// </summary>
/// <returns></returns>
//[AuthorizeRedirect(Roles = InitRights.CONST_角色管理)]
[Area("Admin")]
public JsonResult GetHtmlList(string columns)
{
var modelist = _basRoleServide.GetBasRoleList();
Table table = new Table(columns, true);
foreach (var model in modelist)
{
table.AddCol(model.RoleId);
table.AddCol("text-align:left;padding-left:20px;", "", model.RName);
table.AddCol("text-align:left;padding-left:20px;", "", model.Code);
table.AddCol(string.Format("<input type='text' value='{0}' oldvalue='{0}' roleId='{1}' style='width:40px;'/>", model.SortId, model.RoleId));
table.AddCol(model.CreateUser);
table.AddCol(model.CTime.ToUnityString(1));
table.AddCol(model.UpdateUser);
table.AddCol(model.UTime.ToUnityString(1));
table.AddRow();
}
var json = new
{
rowsList = table.GetRows()
};
return Json(json);
}
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Details)]
[Area("Admin")]
public ActionResult Details(int? id)
{
if (!id.HasValue)
return View(new Bas_Role());
else
return View(_basRoleServide.Get(id.Value));
}
#endregion
#region
[Area("Admin")]
[HttpGet]
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Edit)]
public ActionResult Edit(int? id)
{
var model = new Bas_Role();
if (id.HasValue)
model = _basRoleServide.Get(id.Value);
return View(model);
}
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Edit)]
[Area("Admin")]
public JsonResult Edit(Bas_Role model)
{
//if (!ModelState.IsValid)
// return JsonHandler.ValidateFailMessage();
if (model.RoleId == 0)
{
model.CTime = DateTime.Now;
model.CreateUser = UserId;
_basRoleServide.AddBasRole(model);
return JsonHandler.InsertMessage(errors, true);
}
else
{
model.UTime = DateTime.Now;
model.UpdateUser = UserId;
_basRoleServide.UpdateBasRole(model);
return JsonHandler.UpdateMessage(errors, true);
}
}
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Delete)]
[Area("Admin")]
public JsonResult Delete(Bas_Role model)
{
if (model == null)
return JsonHandler.ManageMessage("参数不对!", false);
_basRoleServide.DeleteBasRole(model);
return JsonHandler.DeleteMessage(errors, true);
}
#endregion
#region
/// <summary>
/// 更新列表数据排序
/// </summary>
/// <returns></returns>
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Other1)]
[Area("Admin")]
public JsonResult Sort(string roleIds, string sortIds)
{
_basRoleServide.Sort(roleIds, sortIds);
return JsonHandler.ManageMessage(errors, true);
}
#endregion
#region
[HttpPost]
/// <summary>
/// 获取角色树形
/// </summary>
/// <returns></returns>
[Area("Admin")]
public JsonResult GetRoleTree()
{
return Json(_basRoleServide.GetRoleTree());
}
#endregion
#region
[HttpPost]
/// <summary>
/// 获取角色树形
/// </summary>
/// <returns></returns>
[Area("Admin")]
public JsonResult GetRoleAllTree()
{
List<object> obj = new List<object>() { new { id = 0, text = "所有角色", iconCls = " icon-group", children = _basRoleServide.GetRoleTree() } };
return Json(obj);
}
#endregion
}
}