예제 #1
0
        public ActionResult MenuManage()
        {
            TS_MENUDTO dto = new TS_MENUDTO();
            //获取完成工差列表
            PageResult <TS_MENU> ef = service.GetMenus(dto);
            //获取分页数据
            BASEPAGE page = AUTOMAPING.Mapping <BASEPAGE>(ef);

            this.HttpContext.Session["Page"] = page;
            //EF实体数据转换为DTO
            dto.Menus = MAPPING.ConvertEntityToDtoList <TS_MENU, TS_MENUDTO>(ef.DataList);
            return(View(dto));
        }
예제 #2
0
        /// <summary>
        /// 查询菜单
        /// </summary>
        /// <returns></returns>
        public ActionResult QueryMenu()
        {
            TS_MENUDTO dto = new TS_MENUDTO();

            dto.Menus = MAPPING.ConvertEntityToDtoList <TS_MENU, TS_MENUDTO>(service.GetMenus());
            return(View(dto));
        }
예제 #3
0
        /// <summary>
        /// 检查用户登录
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) ||
                filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
            {
                return;                                                   //表示支持控制器、action的AllowAnonymousAttribute
            }
            var sessionUser = HttpContext.Current.Session["CurrentUser"]; //使用session

            //var memberValidation = HttpContext.Current.Request.Cookies.Get("CurrentUser");//使用cookie
            //也可以使用数据库、nosql等介质
            if (sessionUser == null || !(sessionUser is CurrentUser))
            {
                HttpContext.Current.Session["CurrentUrl"] = filterContext.RequestContext.HttpContext.Request.RawUrl;
                //filterContext.Result = new RedirectResult(this._loginPath);
                //filterContext.HttpContext.Response.Write("<script>window.parent.location.href='/Auth/Login';</script>");
                filterContext.Result = new RedirectResult(this._loginPath);
            }
            else
            {
                CurrentUser    currentUser = (CurrentUser)filterContext.RequestContext.HttpContext.Session["CurrentUser"];
                string         url         = filterContext.RequestContext.HttpContext.Request.RawUrl;
                List <TS_MENU> menus       = new List <TS_MENU>();
                List <TS_MENU> useMenus    = new List <TS_MENU>();
                var            logger      = NF.Framework.Logger.CreateLogger(this.GetType());
                object         oMenu       = Caching.Get("menu" + currentUser.Id);
                if (oMenu != null)
                {
                    logger.Info($"menu{ currentUser.Id} 菜单使用缓存");
                    return;
                }
                else
                {
                    logger.Info($"menu{ currentUser.Id} 菜单刷新");
                    //menus 一级菜单
                    menus = service.GetMenus(1);
                    List <TS_FUNCTIONDTO> fDtos = currentUser.MenuFuncs;
                    foreach (var m in menus)
                    {
                        //useMenus.Add(m);
                        if (fDtos.ExistsOrDefault <TS_FUNCTIONDTO>(x => x.MenuID == m.C_ID))
                        {
                            useMenus.Add(m);
                        }
                    }
                }
                List <TS_MENUDTO> menuDtos = MAPPING.ConvertEntityToDtoList <TS_MENU, TS_MENUDTO>(useMenus);
                List <TS_MENUDTO> newMenus = new List <TS_MENUDTO>();
                List <TS_MENUDTO> pMenus   = menuDtos.FindAll(x => x.C_PARENT_ID == null);
                foreach (var parent in pMenus)
                {
                    var parentDto = parent;
                    List <TS_MENUDTO> childrenMenus = menuDtos.FindAll(x => x.C_PARENT_ID == parent.C_ID);
                    if (childrenMenus.Count > 0)
                    {
                        foreach (var children in childrenMenus)
                        {
                            parentDto.Menus.Add(children);
                        }
                    }
                    newMenus.Add(parentDto);
                }

                List <MENUDTO> menu = MAPPING.ConvertMenu(newMenus);

                string strMenu = NF.Framework.SerializationHelper.JsonSerialize(menu);
                string path    = "/Common/main.html";
                if (currentUser.Type == "1")
                {
                    path = "/Common/main2.html";
                }
                string newUrl = "{ id: '0',text: '首页',icon: 'icon-cog',url: '',menus: [{ id: '00',text: '首页',icon: 'icon-glass',close: false,url: '" + path + "' }]},";
                string str    = strMenu.Insert(1, newUrl);
                Caching.Set("menu" + currentUser.Id, str);
            }
        }