Esempio n. 1
0
        public GetSiteMenusResponse GetSiteMenus(GetSiteMenusRequest request)
        {
            var response = new GetSiteMenusResponse();
            var menus = new List<Data.Entities.Menu>();

            if (request.ParentId != null)
            {
                menus = DataContext.Menus.Where(x => x.IsActive == true && x.ParentId == request.ParentId && x.RoleGroups.Select(y => y.Id).Contains(request.RoleId)).OrderBy(x => x.Order).ToList();
            }
            else
            {
                menus = DataContext.Menus.Where(x => x.IsActive == true && x.ParentId == null && x.RoleGroups.Select(y => y.Id).Contains(request.RoleId) || x.ParentId == 0 && x.RoleGroups.Select(y => y.Id).Contains(request.RoleId)).OrderBy(x => x.Order).ToList();
            }

            if (request.IncludeChildren)
            {
                var logout = new Data.Entities.Menu
                {
                    Name = "Logout",
                    IsActive = true,
                    Url = "/Account/Logoff",
                    Parent = null,
                    Icon = "logout.png"
                };
                menus.Add(logout);

                //looping to get the children, we dont use Include because only include 1st level child menus
                foreach (var menu in menus)
                {
                    menu.Menus = this._GetMenuChildren(menu.Id, request.RoleId);
                    //if (menu.Name == "Setting" && menu.IsRoot == true) {
                    //    menu.Menus.Add(logout);
                    //}
                }
            }

            response.Menus = menus.MapTo<GetSiteMenusResponse.Menu>();
            ////set root menu active / selected
            ////set root menu active / selected
            //if (request.MenuId == null || request.MenuId == 0)
            //{
            //    response.MenuIdActive = DataContext.Menus.Where(x => x.ParentId == null || x.ParentId == 0).Select(x => x.Id).First();
            //}
            //else
            //{

            //}

            return response;
        }
Esempio n. 2
0
        public ActionResult SiteMap()
        {
            //get menu active by url request
            //var rootMenuActive = TempData["RootMenuActive"].MapTo<Data.Entities.Menu>();
            var rootMenuActive = TempData["RootMenuActive"].MapTo<Services.Responses.Menu.GetSiteMenuActiveResponse>();
            // var userService = ObjectFactory.Container.GetInstance<IUserService>();
            //var AuthUser = userService.GetUserByName(new GetUserByNameRequest { Name = HttpContext.User.Identity.Name });
            var sessionData = (UserProfileSessionData)this.Session["LoginUser"];
            var menus = new GetSiteMenusResponse();
            if (sessionData != null)
            {
                //var role = AuthUser.Role;
                menus = _menuService.GetSiteMenus(new GetSiteMenusRequest() { IncludeChildren = true, RoleId = sessionData.RoleId });
                menus.RootMenuIdActive = rootMenuActive.Id;
                menus.SelectedMenu = rootMenuActive.SelectedMenu.MapTo<Services.Responses.Menu.GetSiteMenusResponse.Menu>();
                menus.History = rootMenuActive.HistoryMenu;
            }

            return PartialView("_SiteMap", menus);
        }