public ActionResult Edit(ActionInfo actionInfo) { string result = "no"; //判断是否桌面菜单 if (actionInfo.IsMenu == 1) { //是 actionInfo.MenuIcon = string.IsNullOrWhiteSpace(Request["viewMenuIcon"]) ? ConfigurationManager.AppSettings["DefaultMenuIcon"] : Request["viewMenuIcon"]; } else { //否 actionInfo.MenuIcon = null; } ActionInfo action = ActionInfoBll.GetById(actionInfo.ActionId); action.ModifiedTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); action.ActionTitle = actionInfo.ActionTitle; action.ControllerName = actionInfo.ControllerName; action.ActionName = actionInfo.ActionName; action.IsMenu = actionInfo.IsMenu; action.MenuIcon = actionInfo.MenuIcon; action.Remark = actionInfo.Remark; action.SubBy = UserLogin.UserId; if (action.ActionTitle != string.Empty && ActionInfoBll.Edit(action)) { result = "ok"; } return(Content(result)); }
public ActionResult GetActionInfo() { var pageIndex = Request["page"] != null?int.Parse(Request["page"]) : 1; var pageSize = Request["rows"] != null?int.Parse(Request["rows"]) : 5; var name = Request["name"]; var remark = Request["remark"]; var totalCount = 0; var delFlag = (short)DelFlagEnum.Normal; var actionInfoList = ActionInfoBll.LoadPageEntities(pageIndex, pageSize, out totalCount, a => a.DelFlag == delFlag, a => a.ID, true); var temp = actionInfoList.Select(a => new { ID = a.ID, ActionInfoName = a.ActionInfoName, Sort = a.Sort, Remark = a.Remark, Url = a.Url, HttpMethod = a.HttpMethod, ActionTypeEnum = a.ActionTypeEnum, SubTime = a.SubTime }); return(Json(new { rows = temp, total = totalCount }, JsonRequestBehavior.AllowGet)); }
public ActionResult EditInfo(ActionInfo actionInfo) { actionInfo.ModifiedOn = DateTime.Now; var result = ActionInfoBll.EditEntity(actionInfo) ? "ok" : "no"; return(Content(result)); }
public ActionResult Add(ActionInfo actionInfo) { string result = "no"; if (actionInfo != null && !string.IsNullOrWhiteSpace(actionInfo.ActionTitle) && !string.IsNullOrWhiteSpace(actionInfo.ControllerName) && !string.IsNullOrWhiteSpace(actionInfo.ActionName)) { //判断是否桌面菜单 if (actionInfo.IsMenu == 1) { //是桌面菜单 actionInfo.MenuIcon = string.IsNullOrWhiteSpace(Request["viewMenuIcon"]) ? ConfigurationManager.AppSettings["DefaultMenuIcon"] : Request["viewMenuIcon"]; } else { //否 actionInfo.MenuIcon = null; } actionInfo.AddTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); actionInfo.IsDeleted = 0; actionInfo.SubBy = UserLogin.UserId; if (ActionInfoBll.Add(actionInfo)) { result = "ok"; } } return(Content(result)); }
public ActionResult ShowEditInfo() { var id = int.Parse(Request["id"]); var actionInfo = ActionInfoBll.LoadEntities(a => a.ID == id).FirstOrDefault(); ViewData.Model = actionInfo; return(View()); }
public ActionResult SetUserAction(int uId) { UserInfo userInfo = UserInfoBll.GetById(uId); ViewBag.UserInfo = userInfo; ViewBag.UserActionInfo = userInfo.UserActionInfo.ToList(); ViewData.Model = ActionInfoBll.GetList(a => a.IsDeleted == 0, a => a.ActionTitle).ToList(); return(View()); }
//获取分页数据 public ActionResult GetPageList() { //预处理搜索条件 long searchId; bool isId = long.TryParse(Request["searchId"], out searchId); string searchName = string.IsNullOrEmpty(Request["searchName"]) ? string.Empty : Request["searchName"]; DateTime from, to; bool fromIsDate = DateTime.TryParse(Request["from"], out from); bool toIsDate = DateTime.TryParse(Request["to"], out to); int pageIndex = Request["page"] != null?int.Parse(Request["page"]) : 1; int pageSize = Request["rows"] != null?int.Parse(Request["rows"]) : 5; //进行分页查询 int totalCount; WhereHelper <ActionInfo> wh = new WhereHelper <ActionInfo>(); wh.Equal("IsDeleted", (byte)0); if (isId) { wh.Equal("ActionId", searchId); } if (searchName != string.Empty) { wh.Contains("ActionTitle", searchName); } if (fromIsDate) { wh.StrGreater("AddTime", from.ToString("yyyy-MM-dd HH:mm:ss")); } if (toIsDate) { wh.StrLess("AddTime", to.ToString("yyyy-MM-dd") + " 23:59:59"); } var actionList = ActionInfoBll.GetPageList <long>(wh.GetExpression(), a => a.ActionId, false, pageIndex, pageSize, out totalCount); var uList = UserInfoBll.GetList <int>(us => true); //构造新匿名对象防止导航属性循环引用 var result = from a in actionList from uu in uList where a.SubBy == uu.UserId select new { ActionId = a.ActionId, ActionTitle = a.ActionTitle, IsMenu = a.IsMenu, ControllerName = a.ControllerName, ActionName = a.ActionName, Remark = a.Remark, AddTime = a.AddTime, ModifiedTime = a.ModifiedTime, SubBy = uu.RealName != null && uu.RealName != "" ? uu.RealName : uu.Username }; return(Json(new { total = totalCount, rows = result }, JsonRequestBehavior.AllowGet)); }
public ActionResult SetAction(int id) { //TODO 根据id查出当前用户 var user = UserInfoBll.LoadEntities(u => u.Id == id).FirstOrDefault(); //把所有的权限发送到前台 ViewBag.AllActions = ActionInfoBll.LoadEntities(a => a.DelFlag == delNormal).ToList(); //把当前用户所有的特殊权限查询出来,发送到前台 ViewBag.AllExistActions = user.R_UserInfo_ActionInfo.ToList(); return(View(user)); }
public ActionResult CheckExist(string aName) { string result = "no"; var temp = ActionInfoBll.GetList <int>(a => (a.IsDeleted == 0) && (a.ActionTitle == aName)).FirstOrDefault(); if (temp == null) { result = "ok"; } return(Content(result)); }
public ActionResult DeleteActionInfo() { var actionId = int.Parse(Request["actionId"]); var actionInfo = ActionInfoBll.LoadEntities(a => a.ID == actionId).FirstOrDefault(); if (ActionInfoBll.DeleteEntity(actionInfo)) { return(Content("ok")); } else { return(Content("no")); } }
// 完成权限的添加 public ActionResult AddActionInfo(ActionInfo actionInfo) { actionInfo.DelFlag = 0; actionInfo.ModifiedOn = DateTime.Now;; actionInfo.SubTime = DateTime.Now; actionInfo.Url = actionInfo.Url.ToLower(); var paths = Request.Path.Split('/'); actionInfo.ControllerName = paths[1]; actionInfo.ActionMethodName = paths[2]; actionInfo.IconWidth = 100; actionInfo.IconHeight = 100; ActionInfoBll.AddEntity(actionInfo); return(Content("ok")); }
//为权限配置角色信息 public ActionResult SetActionRole() { var actionId = int.Parse(Request["actionId"]); var actionInfo = ActionInfoBll.LoadEntities(a => a.ID == actionId).FirstOrDefault(); ViewBag.ActionInfo = actionInfo; var delFlag = (short)DelFlagEnum.Normal; var allRoleList = RoleInfoBll.LoadEntities(a => a.DelFlag == delFlag).ToList(); var extRoleIdList = (from r in actionInfo.RoleInfo select r.ID).ToList(); ViewBag.RoleList = allRoleList; ViewBag.RoleIdList = extRoleIdList; return(View()); }
/// <summary> /// 展示用户权限 /// </summary> /// <returns></returns> public ActionResult ShowUserAction() { //当前用户ID int userID = Convert.ToInt32(Request["userID"]); //当前用户 var userInfo = UserInfoBll.LoadEntities(u => u.ID == userID).FirstOrDefault(); //当前用户已经拥有的权限(中间表) var userActionList = (from a in userInfo.R_UserInfo_ActionInfo select a).ToList(); //获取所有权限 var actionList = ActionInfoBll.LoadEntities(a => a.DelFlag == (short)DeleteEnumType.Normal).ToList(); //放在ViewBag ViewBag.userInfo = userInfo; ViewBag.userActionList = userActionList; ViewBag.actionList = actionList; return(View()); }
//完成对权限的角色分配 public ActionResult SetActionRoleInfo() { var actionId = int.Parse(Request["actionId"]); var list = new List <int>(); var allKeys = Request.Form.AllKeys;//获取所有表单中name的属性值 foreach (var key in allKeys) { if (key.StartsWith("cba_")) { var str = key.Replace("cba_", ""); list.Add(int.Parse(str)); } } var result = ActionInfoBll.SetActionRoleInfo(actionId, list)?"ok":"no"; return(Content(result)); }
/// <summary> /// 为用户分配权限 /// </summary> /// <returns></returns> public ActionResult SetUserActionInfo() { var userId = int.Parse(Request["userId"]); //查询要分配权限的用户信息 var userInfo = UserInfoBll.LoadEntities(u => u.UserID == userId).FirstOrDefault(); ViewBag.UserInfo = userInfo; //获取所有的权限信息 var delFlag = (short)DelFlagEnum.Normal; var allActionList = ActionInfoBll.LoadEntities(a => a.DelFlag == delFlag).ToList(); ViewBag.ActionList = allActionList; //获取所有用户已经有的权限 var allActionIdList = userInfo.R_UserInfo_ActionInfo.ToList(); ViewBag.ActionIdList = allActionIdList; return(View()); }
public ActionResult DeleteActionInfoList() { var strId = Request["strId"]; var strIds = strId.Split(','); var listId = new List <int>(); foreach (var id in strIds) { listId.Add(int.Parse(id)); } if (ActionInfoBll.DeleteEntities(listId)) { return(Content("ok")); } else { return(Content("no")); } }
public ActionResult Delete(string strId) { string result = "no"; string[] strIds = strId.Split(','); List <int> idList = new List <int>(); int temp; foreach (string item in strIds) { if (int.TryParse(item, out temp)) { idList.Add(temp); } } if (idList != null && ActionInfoBll.Delete(idList)) { result = "ok"; } return(Content(result)); }
public ActionResult SetRoleAction(int rId) { ViewBag.RoleInfo = RoleInfoBll.GetById(rId); ViewData.Model = ActionInfoBll.GetList(a => a.IsDeleted == 0, a => a.ActionTitle).ToList(); return(View()); }
//首页 public ActionResult Index() { #region 查找待办事项信息并放在ViewData中 List <QuickEntryViewModel> ltEntry = new List <QuickEntryViewModel>(); ViewBag.CurrentUser = UserLogin.UserName; var aSteps = WFStepBll.GetList(s => (s.NextId == UserLogin.UserId) && s.IsEnd == 0, s => s.StepId); var aInstances = from s in aSteps select s.WFInstance; AddEntryViewToList(ltEntry, aInstances); var rInstances = WFInstanceBll.GetList(i => (i.SubBy == UserLogin.UserId) && (i.InstanceState == 1), i => i.InstanceId); AddEntryViewToList(ltEntry, rInstances); ViewData["Entry"] = ltEntry; #endregion #region 主菜单过滤 //准备目标集合 List <MenuViewModel> listMenu = new List <MenuViewModel>(); //获取所有的桌面菜单 List <ActionInfo> aList = ActionInfoBll.GetList(a => a.IsDeleted == 0 && a.IsMenu == 1, a => a.ActionTitle).ToList(); //获取当前登录的用户的对象 UserInfo userInfo = UserInfoBll.GetById(UserLogin.UserId); //遍历所有桌面菜单,逐个判断是否有权限 foreach (var actionInfo in aList) { //根据当前数据,构造一个菜单对象 MenuViewModel menu = new MenuViewModel() { ActionTitle = actionInfo.ActionTitle, ControllerName = actionInfo.ControllerName, ActionName = actionInfo.ActionName, MenuIcon = actionInfo.MenuIcon }; //查找否决中是否允许,如果允许,直接加入目标集合 if (UserActionInfoBll.GetList <int>(ua => (ua.ActionId == actionInfo.ActionId) && (ua.UserId == UserLogin.UserId) && (ua.IsAllow == 1)).Count() > 0) { listMenu.Add(menu); continue; } //如果否决没有允许,则查找角色-权限过程 var raList = from r in userInfo.RoleInfo from a in r.ActionInfo where a.ActionId == actionInfo.ActionId select a; if (raList.Count() > 0) { listMenu.Add(menu); } //排除拒绝的特殊权限 var forbidList = from ua in userInfo.UserActionInfo where ua.ActionId == actionInfo.ActionId && ua.IsAllow == 0 select ua; if (forbidList.Count() > 0) { listMenu.Remove(menu); } } #endregion return(View(listMenu)); }
public ActionResult Edit(int aId) { ActionInfo actionInfo = ActionInfoBll.GetById(aId); return(View(actionInfo)); }
//行为前过滤 protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); #region 验证是否有访问权限 ////留个后门,给管理方便,发布时删除 //if (UserLogin.UserName.Equals("admin123")) //{ // return; //} //获取用户以及要访问的url UserInfo userInfo = UserInfoBll.GetById(UserLogin.UserId); string controllerName = RouteData.GetRequiredString("controller"); string actionName = RouteData.GetRequiredString("action"); if (actionName == "CheckExist" || actionName == "GetSelect" || actionName == "CheckPwdRight") { //默认所有人都有验证字段名是否存在、获取下拉列表数据和判断密码是否正确的权限 return; } ActionInfo actionInfo = ActionInfoBll.GetList <int>(a => (a.ControllerName.ToLower().Equals(controllerName.ToLower())) && (a.ActionName.ToLower().Equals(actionName.ToLower())) && a.IsDeleted == 0) .FirstOrDefault(); if (actionInfo == null) { //访问url有误 filterContext.Result = new RedirectResult("/Error.html"); return; } //查询否决,看有无数据 UserActionInfo userActionInfo = UserActionInfoBll.GetList <int>(ua => (ua.UserId == userInfo.UserId) && (ua.ActionId == actionInfo.ActionId)).FirstOrDefault(); if (userActionInfo != null) { //否决表中有数据 if (userActionInfo.IsAllow == 1) { //允许 return; } else { //拒绝,跳转到无权限页面 filterContext.Result = new RedirectResult("/NoAccess.html"); } } else { //否决表中无数据,则通过用户找角色,通过角色找权限 var result = from r in userInfo.RoleInfo from a in r.ActionInfo where a.ActionId == actionInfo.ActionId select a; if (result.Count() > 0) { //有权限 return; } else { //无权限,跳转到无权限页面 filterContext.Result = new RedirectResult("/NoAccess.html"); } } #endregion }