123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using EMIS.Web.Controls;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.ViewModel;
- using EMIS.ViewModel.SystemView;
- using Bowin.Common.Data;
- using Bowin.Common.JSON;
- using Bowin.Web.Controls.Mvc;
- using Bowin.Common.Utility;
- using System.ComponentModel;
- using System.Collections.Concurrent;
- using Bowin.Common.Exceptions;
- namespace EMIS.Web.Controllers.UserManagement
- {
- [Authorization]
- public class RoleController : Controller
- {
- public Lazy<IRoleServices> RoleServices { get; set; }
- public Lazy<IFunctionCodeServices> FunctionCodeServices { get; set; }
- /// <summary>
- /// 教师角色页面
- /// </summary>
- /// <returns></returns>
- public ActionResult List()
- {
- return View();
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- var dataRange = pararms.getExtraInt("DataRange");
- if (dataRange == DropdownList.SELECT_ALL) dataRange = null;
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(RoleServices.Value.GetRoleViewList(configuretView, dataRange, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 学生角色页面
- /// </summary>
- /// <returns></returns>
- public ActionResult StudentList()
- {
- return View();
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult StudentList(QueryParamsModel pararms)
- {
- return base.Json(RoleServices.Value.GetStudentRoleViewList((int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 编辑页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Edit(Guid? roleID)
- {
- RoleView roleView = new RoleView();
- if (roleID != null && roleID != Guid.Empty)
- {
- roleView = RoleServices.Value.GetRoleViewInfo(roleID);
- }
- return View(roleView);
- }
- /// <summary>
- /// 编辑页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult StudentEdit(Guid? roleID)
- {
- RoleView departmentView = new RoleView();
- if (roleID != null && roleID != Guid.Empty)
- {
- departmentView = RoleServices.Value.GetRoleViewInfo(roleID);
- }
- return View(departmentView);
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(RoleView roleView)
- {
- try
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- roleView.TypeID = (int)SYS_RoleType.Teacher;
- RoleServices.Value.Save(roleView);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult StudentEdit(RoleView roleView)
- {
- try
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- roleView.TypeID = (int)SYS_RoleType.Student;
- RoleServices.Value.Save(roleView);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string roleIDs)
- {
- try
- {
- var roleIDList = roleIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
- RoleServices.Value.Delete(roleIDList);
- return base.Json("删除成功!");
- }
- catch (Exception ex)
- {
- return base.Json("删除失败,原因:" + ex.Message + "。");
- }
- }
- /// <summary>
- /// 教师角色授权
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- public ActionResult Authenization(Guid roleID)
- {
- return View();
- }
- /// <summary>
- /// 学生角色授权
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- public ActionResult StudentAuthenization(Guid roleID)
- {
- return View();
- }
- [HttpPost]
- public ActionResult GetAuthenizationTree(Guid roleID)
- {
- var allFunctionCode = FunctionCodeServices.Value.GetAllFunctionCodeViewList().Where(x => x.FunctionCode != "FunStu").ToList();
- var selectedFunctionCode = FunctionCodeServices.Value.GetSelectFunctionCodeViewList(roleID);
- var topTree = allFunctionCode.Where(x => string.IsNullOrEmpty(x.ParentFunctionCode))
- .OrderBy(x => x.OrderNo)
- .Select(x => new TreeItem
- {
- id = x.FunctionCode,
- text = x.FunctionName,
- @checked = selectedFunctionCode.Any(w => w.FunctionCode.Trim() == x.FunctionCode.Trim())
- }).ToList();
- topTree.ForEach(x => BindAuthenizationTreeChildren(allFunctionCode, selectedFunctionCode, x));
- return Json(topTree);
- }
- [HttpPost]
- public ActionResult GetStudentAuthenizationTree(Guid roleID)
- {
- var allFunctionCode = FunctionCodeServices.Value.GetAllFunctionCodeViewList().Where(x => x.FunctionCode != "Fun").ToList();
- var selectedFunctionCode = FunctionCodeServices.Value.GetSelectFunctionCodeViewList(roleID);
- var topTree = allFunctionCode.Where(x => string.IsNullOrEmpty(x.ParentFunctionCode))
- .OrderBy(x => x.OrderNo)
- .Select(x => new TreeItem
- {
- id = x.FunctionCode,
- text = x.FunctionName,
- @checked = selectedFunctionCode.Any(w => w.FunctionCode.Trim() == x.FunctionCode.Trim())
- }).ToList();
- topTree.ForEach(x => BindAuthenizationTreeChildren(allFunctionCode, selectedFunctionCode, x));
- return Json(topTree);
- }
- private void BindAuthenizationTreeChildren(IList<FunctionCodeView> allFunctionCode, IList<FunctionCodeView> selectedFunctionCode, TreeItem treeItem)
- {
- try
- {
- treeItem.children = allFunctionCode.Where(x => (x.ParentFunctionCode ?? "").Trim() == treeItem.id.Trim())
- .OrderBy(x => x.OrderNo)
- .Select(x => new TreeItem
- {
- id = x.FunctionCode,
- text = x.FunctionName,
- @checked = selectedFunctionCode.Any(w => w.FunctionCode.Trim() == x.FunctionCode.Trim())
- }).ToList();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- treeItem.children.ForEach(x => BindAuthenizationTreeChildren(allFunctionCode, selectedFunctionCode, x));
- }
- [HttpPost]
- public ActionResult SaveAuthenization(Guid roleID, string functionCodeList)
- {
- try
- {
- var functionCodes = functionCodeList.Split(',').ToList();
- FunctionCodeServices.Value.SaveAuthenization(roleID, functionCodes);
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "保存成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "保存失败!" + ex.Message
- });
- }
- }
- /// <summary>
- /// 数据范围设置
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- public ActionResult DataRange(Guid roleID)
- {
- return View();
- }
- [HttpPost]
- public ActionResult DataRangeAll(Guid roleID)
- {
- var rangeData = this.RoleServices.Value.GetRoleDataRange(roleID);
- return Json(new JsonDataGridResult<RoleDataRangeView> { rows = rangeData, total = rangeData.Count });
- }
- [HttpPost]
- public ActionResult SaveDataRange(Guid roleID, string dataRangeJson)
- {
- try
- {
- RoleDataRangeSaveView data = new RoleDataRangeSaveView();
- data.RoleID = roleID;
- data.DataRangeViewList = dataRangeJson.JsonToObject<List<RoleDataRangeView>>();
- data.DataRangeViewList.RemoveAll(x => (x.DataRangeID ?? DropdownList.SELECT_ALL) == DropdownList.SELECT_ALL);
- data.DataRangeViewList.ForEach(x => x.RoleID = roleID);
- this.RoleServices.Value.SaveDataRange(data.RoleID, data.DataRangeViewList);
- return Json(new ReturnMessage
- {
- IsSuccess = true,
- Message = "保存成功"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage
- {
- IsSuccess = false,
- Message = "保存失败!" + ex.Message
- });
- }
- }
- [HttpPost]
- public ActionResult RoleDropdownList(DropdownListBindType? bindType)
- {
- List<DropdownListItem> list = RoleServices.Value.GetRoleViewList(new ConfiguretView(), null).Select(x => new DropdownListItem { Text = x.RoleName, Value = x.RoleID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- //[HttpPost]
- //public ActionResult SysRoleDropdownList(DropdownListBindType? bindType)
- //{
- // var enumType = typeof(SYS_RoleType);
- // var list = EnumHelper.EnumToDictionary(enumType).Select(s => new DropdownListItem { Text = s.Value, Value = s.Key }).ToList();
- // DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- // DropdownList.FormatDropdownItemList(dbt, list);
- // return base.Json(list);
- //}
- [HttpPost]
- public ActionResult StudentRoleDropdownList(DropdownListBindType? bindType)
- {
- List<DropdownListItem> list = RoleServices.Value.GetStudentRoleViewList().Select(x => new DropdownListItem { Text = x.RoleName, Value = x.RoleID.ToString() }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- [HttpPost]
- public ActionResult ListAll()
- {
- var list = RoleServices.Value.GetEnabledRoleViewList();
- return base.Json(new JsonDataGridResult<RoleView> { rows = list, total = list.Count });
- }
- [HttpPost]
- public ActionResult StudentVerification(Guid? roleID, int studentTypeID, string roleName)
- {
- try
- {
- RoleServices.Value.StudentVerification(roleID ?? Guid.Empty, studentTypeID, roleName);
- return base.Json("成功");
- }
- catch (Exception ex)
- {
- return base.Json("保存失败," + ex.Message);
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult StudentExcel(QueryParamsModel pararms)
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- var dt = RoleServices.Value.GetStudentRoleViewList().Select(x => new
- {
- x.RoleName,
- x.Description
- }).ToTable();
- string[] liststring = { "类型名称", "备注" };
- neh.Export(dt, liststring, "学生角色信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/Role/StudentList").AddMenuParameter()
- });
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel()
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- //避开全选值
- var dataRange = Request.Form["DataRange"].ParseStrTo<int>();
- if (dataRange == DropdownList.SELECT_ALL) dataRange = null;
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- var dt = RoleServices.Value.GetRoleViewList(configuretView, dataRange).Select(x => new
- {
- x.RoleName,
- x.DefaultDataRangeDesc,
- x.RecordStatusDesc,
- x.Description
- }).ToTable();
- string[] liststring = { "类型名称", "数据范围", "是否可用", "备注" };
- neh.Export(dt, liststring, "用户类型信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/Role/List").AddMenuParameter()
- });
- }
- }
- }
|