Пример #1
0
        public JsonNetResult JsonMenus()
        {
            var mainMenus = new MainMenusModel
            {
                Menus       = new List <MenuModel>(),
                IsAdmin     = this.IsAdmin,
                UserAccount = UserContext.Account,
                UserName    = UserContext.Name
            };

            IList <SystemFunctionEntity> funs;

            if (this.IsAdmin)
            {
                funs = new List <SystemFunctionEntity>();
                funs.Add(new SystemFunctionService().GetSettingFunction());
            }
            else
            {
                if (this.UserContext.HospitalOrVendor)
                {
                    var hospitalId = string.IsNullOrEmpty(this.UserContext.CurrentHospital)
                        ? this.UserContext.RootUnitId : this.UserContext.CurrentHospital;
                    funs = new SystemFunctionService().GetUserFunctions(hospitalId, this.UserContext.UserId);
                }
                else
                {
                    funs = new SystemFunctionService().GetUserFunctions(this.UserContext.RootUnitId, this.UserContext.UserId);
                }
            }
            foreach (var fun in funs)
            {
                var menu = new MenuModel
                {
                    Id       = fun.Id,
                    Title    = fun.Title,
                    Url      = fun.Url,
                    SubMenus = new List <MenuModel>()
                };
                menu.SubMenus = fun.SubFunctions.Select(item => new MenuModel
                {
                    Id    = item.Id,
                    Title = item.Title,
                    Url   = item.Url
                }).ToList();

                mainMenus.Menus.Add(menu);
            }
            var loginInfo = LoginInfo();

            return(JsonNet(new ResponseResult(true, new { mainMenus, loginInfo })));
        }
Пример #2
0
        public PartialViewResult Menus()
        {
            var mainMenus = new MainMenusModel
            {
                Menus   = new List <MenuModel>(),
                IsAdmin = this.IsAdmin
            };

            IList <SystemFunctionEntity> funs;

            if (this.IsAdmin)
            {
                funs = new List <SystemFunctionEntity>();
                funs.Add(new SystemFunctionService().GetSettingFunction());
            }
            else
            {
                if (this.UserContext.HospitalOrVendor)
                {
                    var hospitalId = string.IsNullOrEmpty(this.UserContext.CurrentHospital)
                        ? this.UserContext.RootUnitId : this.UserContext.CurrentHospital;
                    funs = new SystemFunctionService().GetUserFunctions(hospitalId, this.UserContext.UserId);
                }
                else
                {
                    funs = new SystemFunctionService().GetUserFunctions(this.UserContext.RootUnitId, this.UserContext.UserId);
                }
            }

            foreach (var fun in funs)
            {
                var menu = new MenuModel
                {
                    Id       = fun.Id,
                    Title    = fun.Title,
                    Url      = fun.Url,
                    SubMenus = new List <MenuModel>()
                };
                menu.SubMenus = fun.SubFunctions.Select(item => new MenuModel
                {
                    Id    = item.Id,
                    Title = item.Title,
                    Url   = item.Url
                }).ToList();

                mainMenus.Menus.Add(menu);
            }

            return(PartialView("~/Views/Main/_Menus.cshtml", mainMenus));
        }
Пример #3
0
        public JsonNetResult GetPrivilegesAdmin(string unitId)
        {
            if (string.IsNullOrEmpty(unitId))
            {
                return(JsonNet(new ResponseResult(false, "The unit id is empty.")));
            }
            var           functions     = new SystemFunctionService().GetAll().ToList();
            List <object> alTree        = new List <object>();
            var           mainFunctions = new List <SystemFunctionEntity>();
            var           userPri       = new SystemPrivilegeService().GetByObjectId(unitId).ToList().Where(m => m.Operate);
            var           funKeyList    = new List <Funkey>
            {
                Funkey.User,
                Funkey.HospitalSetting,
                Funkey.HospitalSettingUnit,
                Funkey.Product,
                Funkey.VendorSettingUnit,
                Funkey.VendorSetting,
            };

            if (!this.IsAdmin)
            {
                var mainPrivileges = new SystemPrivilegeService().GetByObjectId(UserContext.UnitId).Where(m => m.Operate).ToList();//主单位的权限
                mainPrivileges.ForEach(m =>
                {
                    if (funKeyList.Any(j => j.ToString() == m.FunKey))
                    {
                        return;
                    }
                    if (functions.FirstOrDefault(j => j.FunKey == m.FunKey) != null)
                    {
                        mainFunctions.Add(functions.FirstOrDefault(j => j.FunKey == m.FunKey));
                    }
                });
                mainFunctions.AddRange(functions.Where(m => string.IsNullOrWhiteSpace(m.ParentId)));
            }
            else
            {
                mainFunctions = functions;
            }
            mainFunctions.Where(m => string.IsNullOrWhiteSpace(m.ParentId)).ToList().ForEach(m =>
            {
                List <SystemFunctionModel> childNode = mainFunctions.Where(j => j.ParentId == m.Id).Select(j => new SystemFunctionModel
                {
                    Id           = j.Id,
                    Title        = j.Title,
                    IsMenu       = j.IsMenu,
                    FunKey       = j.FunKey,
                    Url          = j.Url,
                    ParentId     = j.ParentId,
                    IsActive     = j.IsActive,
                    Sequence     = j.Sequence,
                    DisplayMode  = j.DisplayMode,
                    SubFunctions = j.SubFunctions,
                    Operate      = userPri.Any(w => w.FunKey == j.FunKey && w.Operate)
                }).ToList();
                if (childNode.Any())
                {
                    alTree.Add(new { parent = m, childNode });
                }
            });
            return(JsonNet(new ResponseResult(true, new
            {
                UnitId = unitId,
                Functions = alTree
            })));
        }
Пример #4
0
 static AuthorizationAttribute()
 {
     ms_UserFunctionsMap = new Dictionary <string, IList <string> >();
     ms_Service          = new SystemFunctionService();
 }