Esempio n. 1
0
        //[ChildActionOnly]
        public ActionResult LoadMenu()
        {
            MenuViewModel menuVM   = new MenuViewModel();
            string        userName = HttpContext.User.Identity.Name;

            if (!String.IsNullOrEmpty(userName))
            {
                AspNetUser userResult = UserManager.FindByName(userName);
                if (userResult != null)
                {
                    var roles = userResult.AspNetRoles.ToList();
                    if (roles.Count > 0)
                    {
                        IList <MenuRight> menuItems = menuRightService.FindMenuItemsByRoleId(roles[0].Id).ToList();

                        //save menu permissions in session
                        string[] userPermissions = menuItems.Select(user => user.Menu.PermissionKey).ToArray();
                        Session["UserPermissionSet"] = userPermissions;

                        menuVM = new MenuViewModel
                        {
                            MenuRights  = menuItems,
                            MenuHeaders = menuItems.Where(x => x.Menu.IsRootItem)
                        };
                    }
                }
            }
            return(View(menuVM));
        }
Esempio n. 2
0
        //when isForce =  true it sets the value, no matter session has or not
        public void SetUserDetail()
        {
            Session["FullName"] = Session["UserID"] = string.Empty;

            if (!User.Identity.IsAuthenticated)
            {
                return;
            }
            AspNetUser result =
                HttpContext.GetOwinContext()
                .GetUserManager <ApplicationUserManager>()
                .FindById(User.Identity.GetUserId());
            string role =
                HttpContext.GetOwinContext()
                .Get <ApplicationRoleManager>()
                .FindById(result.AspNetRoles.ToList()[0].Id)
                .Name;

            Session["FirstName"]     = result.FirstName;
            Session["LastName"]      = result.LastName;
            Session["EmployeeEmail"] = result.Email;
            Session["UserID"]        = result.Id;
            if (result.Employees.Any())
            {
                Session["FullName"]   = result.Employees.FirstOrDefault().FullName;
                Session["EmployeeID"] = result.Employees.FirstOrDefault().EmployeeId;
            }
            else
            {
                Session["FullName"] = result.FirstName;
            }
            Session["RoleName"] = role;

            //Load Menu and Set Permissions
            IList <MenuRight> menuItems = menuRightService.FindMenuItemsByRoleId(result.AspNetRoles.ToList()[0].Id).ToList();

            //Save menu in sessions
            Session["MenuItemsSet"] = menuItems;
            //save menu permissions in session
            Session["UserPermissionSet"] = menuItems.Select(user => user.Menu.PermissionKey).ToArray();
        }
Esempio n. 3
0
        public ActionResult LoadMenu()
        {
            MenuViewModel menuVM = new MenuViewModel();
            //string userName = HttpContext.User.Identity.Name;
            //if (!String.IsNullOrEmpty(userName))
            //{
            //ApplicationUser userResult = UserManager.FindByEmail(userName);
            //IList<IdentityUserRole> roles = userResult.Roles.ToList();
            //if (roles.Count > 0)
            //{
            IQueryable <MenuRight> menuItems = menuRightService.FindMenuItemsByRoleId("73953B69-8C5A-458F-A75B-399EF9E16371");

            //save menu items in session
            //Session["UserPermissionSet"] = menuItems;

            menuVM = new MenuViewModel
            {
                MenuRights  = menuItems,
                MenuHeaders = menuItems.Where(x => x.Menu.IsRootItem)
            };
            //}
            //}
            return(View(menuVM));
        }