Пример #1
0
        private RightTree GetNode(List <ARolePermissionRelation> rolepers)
        {
            RightTree retree = new RightTree()
            {
                id       = "0",
                _checked = false,
                text     = "选择权限",
                url      = "",
                children = new List <RightTree>()
            };
            var listmodules = CacheAccess.GetModules(_moduleContract).Where(w => w.IsEnabled && !w.IsDeleted).ToList();
            var parmodules  = listmodules.Where(c => c.ParentId == null).ToList();

            foreach (var item in parmodules)
            {
                var tre = new RightTree()
                {
                    id       = item.Id + "",
                    text     = item.ModuleName,
                    url      = "",
                    children = GetChild(item.Id, rolepers, listmodules),
                    _checked = false,
                    msg      = item.Description
                };
                tre._checked = tre.children.Any(c => c._checked);
                tre._isShow  = tre.children.Any(x => x._isShow);
                retree.children.Add(tre);
            }
            retree._checked = retree.children.Any(x => x._checked);
            retree._isShow  = retree.children.Any(x => x._isShow);
            return(retree);
        }
Пример #2
0
        public ActionResult GetChilById()
        {
            //GetChilById?_pid
            OperationResult resul = new OperationResult(OperationResultType.Error);
            var             parid = InputHelper.SafeInput(Request["_pid"]);

            if (!string.IsNullOrEmpty(parid))
            {
                int pid = Convert.ToInt32(parid);

                var pmodu = CacheAccess.GetModules(_moduleContract).Single(c => c.Id == pid && c.IsDeleted == false && c.IsEnabled == true);
                if (pmodu != null)
                {
                    var chil = pmodu.Permissions.Select(c => new RightTree()
                    {
                        id       = "c" + c.Id,
                        text     = c.PermissionName,
                        _checked = false,
                        url      = "",
                        msg      = c.Description
                    });
                    return(Json(new ResJson()
                    {
                        obj = chil,
                        msg = "",
                        success = true,
                    }));
                }
            }
            return(Json(resul));
        }
Пример #3
0
        /// <summary>
        /// 载入创建数据
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            var mod = CacheAccess.GetParentModules(_moduleContract, false);

            ViewBag.ModuleF = mod;
            int defauModulId = int.Parse(mod[0].Value);

            ViewBag.ModuleT = CacheAccess.GetModules(_moduleContract).Where(c => c.ParentId == defauModulId && c.IsEnabled == true && c.IsDeleted == false).Select(c => new SelectListItem()
            {
                Value = c.Id.ToString(),
                Text  = c.ModuleName
            }).ToList();
            return(PartialView());
        }
Пример #4
0
        /// <summary>
        /// 载入修改数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult Update(int Id)
        {
            var result = _moduleContract.Edit(Id);
            var li     = CacheAccess.GetModules(_moduleContract).Where(c => c.IsDeleted == false && c.IsEnabled == true && c.ParentId == null).Select(c => new SelectListItem()
            {
                Text     = c.ModuleName,
                Value    = c.Id.ToString(),
                Selected = Id == c.Id
            }).ToList();

            li.Insert(0, new SelectListItem()
            {
                Text  = "下拉选择",
                Value = "0"
            });
            ViewBag.parentModu = li;
            return(PartialView(result));
        }
Пример #5
0
        /// <summary>
        /// 保留菜单上被选中的项
        /// </summary>
        /// <param name="filterContext"></param>
        /// <returns></returns>
        private Module BreadCrumb(ViewResult viewResult, string pageUrl)
        {
            var breadCrumb = new Module();

            try
            {
                var module = CacheAccess.GetModules(_moduleContract).Where(w => w.PageUrl != null).FirstOrDefault(m => m.PageUrl.ToLower().Contains(pageUrl.ToLower()));

                if (module != null)
                {
                    if (module.ParentId != null)
                    {
                        var parentMenu  = CacheAccess.GetModules(_moduleContract).FirstOrDefault(x => x.Id == module.ParentId);
                        var parentModel = new Module
                        {
                            ModuleName = parentMenu.ModuleName,
                            Icon       = parentMenu.Icon
                        };
                        breadCrumb.Children.Add(parentModel);
                    }

                    var childrenModel = new Module
                    {
                        ModuleName = module.ModuleName,
                        Icon       = module.Icon
                    };
                    breadCrumb.Children.Add(childrenModel);

                    breadCrumb.Icon       = module.Icon;
                    breadCrumb.ModuleName = module.ModuleName;
                    breadCrumb.Id         = module.Id;

                    viewResult.ViewBag.ModuleName = module.ModuleName;
                    viewResult.ViewBag.inval      = string.Join("|", this.PageFlag(module.Id));
                }
            }
            catch (Exception ex)
            {
                _Logger.Error("面包屑加载出错,错误如下:" + ex.Message + "。");
            }
            return(breadCrumb);
        }
Пример #6
0
        public ActionResult GetModules(int id)
        {
            OperationResult       resul = new OperationResult(OperationResultType.Error);
            List <SelectListItem> li    = CacheAccess.GetModules(_moduleContract).Where(c => c.ParentId == id && c.IsDeleted == false && c.IsEnabled == true).Select(c => new SelectListItem()
            {
                Text  = c.ModuleName,
                Value = c.Id.ToString()
            }).ToList();

            li.Insert(0, new SelectListItem()
            {
                Text  = "下拉选择",
                Value = ""
            });
            resul = new OperationResult(OperationResultType.Success)
            {
                Data = li
            };
            return(Json(resul));
        }
        private List <int> GetVerifyAdminIds(int departmentId, params string[] onlyFlags)
        {
            var controller = RouteData.Values["controller"].ToString();

            var module = CacheAccess.GetModules(_moduleContract)
                         .Where(c => !c.IsDeleted && c.IsEnabled)
                         .Where(c => c.PageController != null && c.PageAction != null)
                         .Where(c => c.PageController == controller)
                         .FirstOrDefault();

            var permissionIds = CacheAccess.GetPermissions(_permisstionContract)
                                .Where(p => !p.IsDeleted && p.IsEnabled && p.ModuleId == module.Id)
                                .Where(p => onlyFlags.Contains(p.OnlyFlag))
                                .Select(p => p.Id).ToList();


            var adminIds = _adminContract.Administrators.Where(a => !a.IsDeleted && a.IsEnabled)
                           .Where(a => a.JobPosition.Departments.Any(d => d.Id == departmentId))
                           .Where(a => a.Roles.Any(r => r.ARolePermissionRelations.Any(p => permissionIds.Contains(p.PermissionsId.Value))))
                           .Select(a => a.Id)
                           .ToList();

            return(adminIds);
        }
Пример #8
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var administrator = _administratorContract.Administrators.FirstOrDefault(m => m.Id == AuthorityHelper.OperatorId);

            if (administrator == null)
            {
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    filterContext.Result = new JsonResult {
                        Data = new OperationResult(OperationResultType.Error, "你没有权限进行此操作,授权管理员的身份可能已经注销!"), JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                }
                else
                {
                    FormsAuthentication.SignOut();
                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Login", area = "Authorities" }));
                }
            }
            else
            {
                if (_checkMode == CheckMode.Verify)
                {
                    var area = (filterContext.RouteData.DataTokens.ContainsKey("area") ? filterContext.RouteData.DataTokens["area"].ToString() : string.Empty).ToLower();

                    var controller = filterContext.RouteData.Values["controller"].ToString().ToLower();
                    var action     = filterContext.RouteData.Values["action"].ToString().ToLower();
                    if (administrator.Member.MemberName.ToLower() != "admin".ToLower())
                    {
                        try
                        {
                            var module = CacheAccess.GetModules(_moduleContract).Where(c => c.PageController != null && c.PageAction != null)
                                         .FirstOrDefault(c => c.PageController.ToLower() == controller && c.IsDeleted == false && c.IsEnabled == true);

                            if (module == null)
                            {
                                if (filterContext.HttpContext.Request.IsAjaxRequest())
                                {
                                    filterContext.Result = new JsonResult {
                                        Data = new OperationResult(OperationResultType.Error, "你没有权限进行此操作,授权模块" + controller + "不存在!"), JsonRequestBehavior = JsonRequestBehavior.AllowGet
                                    };
                                }
                                else
                                {
                                    FormsAuthentication.SignOut();
                                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Login", area = "Authorities" }));
                                }
                                return;
                            }

                            var mod = GetCurrPermission();
                            if (mod.IsNullOrEmptyThis())
                            {
                                if (filterContext.HttpContext.Request.IsAjaxRequest())
                                {
                                    filterContext.Result = new JsonResult {
                                        Data = new OperationResult(OperationResultType.Error, "你没有权限进行此操作,授权许可不存在!"), JsonRequestBehavior = JsonRequestBehavior.AllowGet
                                    };
                                }
                                else
                                {
                                    FormsAuthentication.SignOut();
                                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Login", area = "Authorities" }));
                                }
                                return;
                            }
                            if (!mod.Exists(e => e.ModuleId == module.Id))
                            {
                                if (filterContext.HttpContext.Request.IsAjaxRequest())
                                {
                                    filterContext.Result = new JsonResult {
                                        Data = new OperationResult(OperationResultType.Error, "你没有权限进行此操作,授权模块" + module.Id + "中的" + action + "许可不存在!"), JsonRequestBehavior = JsonRequestBehavior.AllowGet
                                    };
                                }
                                else
                                {
                                    FormsAuthentication.SignOut();
                                    filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Login", area = "Authorities" }));
                                }
                            }
                            else
                            {
                                var hasper = mod.Where(w => !string.IsNullOrWhiteSpace(w.ActionName)).FirstOrDefault(e => e.ModuleId == module.Id && e.ActionName.ToLower().Trim() == action);

                                if (hasper == null && this.CurrModuleAllActionName(module.Id).Exists(e => e.ToLower() == action))
                                {
                                    if (filterContext.HttpContext.Request.IsAjaxRequest())
                                    {
                                        filterContext.Result = new JsonResult {
                                            Data = new OperationResult(OperationResultType.Error, "你没有权限进行此操作,授权模块" + module.Id + "中的" + action + "许可不存在!"), JsonRequestBehavior = JsonRequestBehavior.AllowGet
                                        };
                                    }
                                    else
                                    {
                                        FormsAuthentication.SignOut();
                                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Login", area = "Authorities" }));
                                    }
                                }

                                //((ViewResult)filterContext.Result).ViewBag.AdminName = administrator.AdminName;
                            }
                            return;
                        }
                        catch (Exception ex)
                        {
                            if (filterContext.HttpContext.Request.IsAjaxRequest())
                            {
                                filterContext.Result = new JsonResult {
                                    Data = new OperationResult(OperationResultType.Error, "你没有权限进行此操作,授权出现异常:" + ex.ToString()), JsonRequestBehavior = JsonRequestBehavior.AllowGet
                                };
                            }
                            else
                            {
                                FormsAuthentication.SignOut();
                                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Login", area = "Authorities" }));
                            }
                        }
                    }
                }
            }
        }
Пример #9
0
        public ActionResult Index()
        {
            ViewBag.modules = CacheAccess.GetModules(_moduleContract, null, true);

            return(View());
        }
Пример #10
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> List()
        {
            GridRequest request = new GridRequest(Request);
            Expression <Func <Module, bool> > predicate = FilterHelper.GetExpression <Module>(request.FilterGroup);
            var data = await Task.Run(() =>
            {
                List <object> objli = new List <object>();
                var count           = 0;

                #region
                var whereli = request.FilterGroup.Rules.Where(x => x.Field == "IsDeleted" || x.Field == "IsEnabled")
                              .Select(x => new
                {
                    x.Field,
                    x.Value
                }).ToList();
                bool isDele   = false;
                bool isEnable = true;
                foreach (var item in whereli)
                {
                    if (item.Field == "IsDeleted")
                    {
                        isDele = item.Value.ToString() == "true" ? true : false;
                    }

                    if (item.Field == "IsEnabled")
                    {
                        isEnable = item.Value.ToString() == "true" ? true : false;
                    }
                }
                #endregion

                //如果没有提供模块父id和模块名,则根据父级模块分页
                var whereearr      = request.FilterGroup.Rules.Select(x => x.Field).ToList();
                List <Module> list = new List <Module>();
                if (whereearr.IndexOf("ParentId") == -1 && whereearr.IndexOf("ModuleName") == -1)
                {
                    var parli = CacheAccess.GetModules(_moduleContract)
                                .Where(predicate.Compile())
                                .Where(c => c.ParentId == null);

                    list = parli.OrderBy(x => x.Sequence).Skip(request.PageCondition.PageIndex).Take(request.PageCondition.PageSize).ToList();
                    List <Administrator> listAdmin = _adminContract.Administrators.ToList();
                    count = parli.Count();
                    foreach (var x in list)
                    {
                        var parent = new
                        {
                            x.Id,
                            ParentId = "",
                            x.ModuleName,
                            x.Icon,
                            x.ModuleType,
                            x.Description,
                            x.PageUrl,
                            x.PageArea,
                            x.PageController,
                            x.IsDeleted,
                            x.IsEnabled,
                            x.Sequence,
                            x.UpdatedTime,
                            x.CreatedTime,
                            //AdminName = x.Operator == null ? "" : x.Operator.AdminName
                            AdminName = listAdmin.FirstOrDefault(k => k.Id == x.OperatorId) == null ? string.Empty : listAdmin.FirstOrDefault(k => k.Id == x.OperatorId).Member.MemberName,
                        };
                        objli.Add(parent);
                        var childs =
                            CacheAccess.GetModules(_moduleContract)
                            .Where(c => c.IsDeleted == isDele && c.IsEnabled == isEnable && c.ParentId == x.Id).OrderBy(c => c.Sequence)
                            .Select(t => new
                        {
                            t.Id,
                            ParentId = x.Id,
                            t.ModuleName,
                            t.Icon,
                            t.ModuleType,
                            t.Description,
                            t.PageUrl,
                            t.PageArea,
                            t.PageController,
                            t.IsDeleted,
                            t.IsEnabled,
                            t.Sequence,
                            t.UpdatedTime,
                            t.CreatedTime,
                            //AdminName = t.Operator == null ? "" : t.Operator.AdminName
                            AdminName = listAdmin.FirstOrDefault(k => k.Id == x.OperatorId) == null ? string.Empty : listAdmin.FirstOrDefault(k => k.Id == x.OperatorId).Member.MemberName,
                        }).ToList();
                        objli.AddRange(childs);
                    }
                }
                //否则查找所有模块
                else
                {
                    var objlist = _moduleContract.Modules.Where <Module, int>(predicate, request.PageCondition, out count).Select(m => new
                    {
                        m.ParentId,
                        m.ModuleName,
                        m.Icon,
                        m.ModuleType,
                        m.Description,
                        m.PageUrl,
                        m.PageArea,
                        m.PageController,
                        m.PageAction,
                        m.onClickScripts,
                        m.Id,
                        m.IsDeleted,
                        m.IsEnabled,
                        m.Sequence,
                        m.UpdatedTime,
                        m.CreatedTime,
                        m.Operator.Member.MemberName,
                    }).ToList();

                    var li = objlist.Where(c => c.ParentId != null).GroupBy(x => x.ParentId);
                    foreach (var _item in li)
                    {
                        var paren = CacheAccess.GetModules(_moduleContract).Where(c => c.Id == _item.Key && c.IsDeleted == isDele && c.IsEnabled == isEnable).Select(x => new
                        {
                            x.Id,
                            ParentId = "",
                            x.ModuleName,
                            x.Icon,
                            x.ModuleType,
                            x.Description,
                            x.PageUrl,
                            x.PageArea,
                            x.PageController,
                            x.IsDeleted,
                            x.IsEnabled,
                            x.Sequence,
                            x.UpdatedTime,
                            x.CreatedTime,
                            AdminName = x.Operator == null ? "" : x.Operator.Member.MemberName
                        }).FirstOrDefault();

                        if (paren != null)
                        {
                            objli.Add(paren);
                            var childs = _item.Select(x => new
                            {
                                x.Id,
                                ParentId = _item.Key,
                                x.ModuleName,
                                x.Icon,
                                x.ModuleType,
                                x.Description,
                                x.PageUrl,
                                x.PageArea,
                                x.PageController,
                                x.IsDeleted,
                                x.IsEnabled,
                                x.Sequence,
                                x.UpdatedTime,
                                x.CreatedTime,
                                AdminName = ""
                            }).ToList();
                            objli.AddRange(childs);
                        }
                    }
                }
                return(new GridData <object>(objli, count, request.RequestInfo));
            });

            return(Json(data, JsonRequestBehavior.AllowGet));
        }