Exemplo n.º 1
0
        public static IEnumerable <NavigateModel> GetCurrentUserActiveNavigates()
        {
            IEnumerable <NavigateModel> navigateModels = Enumerable.Empty <NavigateModel>();

            IWorkContext workContext = ServiceContainer.Resolve <IWorkContext>();

            INavigateService navigateService = ServiceContainer.Resolve <INavigateService>();

            if (workContext.CurrentUser != null)
            {
                var permissions = workContext.CurrentUser.Roles.SelectMany(r => r.Permissions);

                Mapper.Initialize(cfg => cfg.CreateMap <Navigate, NavigateModel>().ForMember(m => m.Children, p => p.Ignore()).ForMember(m => m.Parent, p => p.Ignore()));
                navigateModels = navigateService.GetNavigates().AsQueryable().ProjectTo <NavigateModel>().ToList();

                foreach (var nav in navigateModels)
                {
                    nav.Parent   = navigateModels.SingleOrDefault(n => n.ID == nav.ParentID);
                    nav.Children = navigateModels.Where(n => n.ParentID == nav.ID).ToList();
                    if (!string.IsNullOrWhiteSpace(nav.ControllerName) && !string.IsNullOrWhiteSpace(nav.ActionName))
                    {
                        nav.Active = permissions.Any(p => p.Name == nav.ControllerName + nav.ActionName);
                    }
                }
            }

            return(navigateModels);
        }
 public ActionResult Create()
 {
     ViewBag.Category = new SelectList(navigateService.GetNavigates(), "Name", "Name");
     return(View());
 }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            var nvas = navigateService.GetNavigates().AsQueryable().ProjectTo <NavigateModel>(mapperConfigProvider);

            return(View(nvas.OrderBy(nav => nav.SortOrder)));
        }