Ejemplo n.º 1
0
        public PositionAccessNodeVM(int accessRuleId, int positionId, AccessRuleDataService accessRuleDataService, PositionAccessRuleDataService positionAccessRuleDataService, AccessType access)
            : base(access)
        {
            var accessRule = accessRuleDataService.GetSingle(accessRuleId);
            Title = Common.Properties.Resources.ResourceManager.GetString(accessRule.Name);
            Id = accessRule.Id;
            ParentId =accessRule.Parent != null? accessRule.Parent.Id : -1;
            foreach (var child in accessRule.Children)
            {
                ChildNodes.Add(new PositionAccessNodeVM(child.Id,positionId,accessRuleDataService, positionAccessRuleDataService, Access));
            }

            var positionAccessRule = positionAccessRuleDataService.GetSingle(positionId, accessRuleId);
            if (positionAccessRule != null)
            {
                if (positionAccessRule.Type != null) 
                    PositionAccess = (AccessType) positionAccessRule.Type;
            }
        }
Ejemplo n.º 2
0
        public UserAccessRulesVM(UserVM user, AccessType access):base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentUser = user;
            UserDataService = new UserDataService(UnitOfWork);
            UserDataService.AccessRuleChanged += OnAccessRuleChanged;
            AccessRuleDataService = new AccessRuleDataService(UnitOfWork);
            UserAccessRuleDataService = new UserAccessRuleDataService(UnitOfWork);
            PositionAccessRuleDataService = new PositionAccessRuleDataService(UnitOfWork);

            RootNode = new UserAccessNodeVM(Access) { Title = string.Empty, Id = -1, ParentId = -2 };

            var selectedVms = new ObservableCollection<UserAccessNodeVM>();

            var ruleAccessList = AccessRuleDataService.GetPositionsAccessOfUser(user.Id);

            foreach (var accessRule in AccessRuleDataService.GetActives())
            {
                selectedVms.Add(new UserAccessNodeVM(accessRule.Id, user.Id, AccessRuleDataService, UserAccessRuleDataService, ruleAccessList, Access));
            }

            var allVms = new ObservableCollection<AccessRuleVM>();
            foreach (var accessRule in AccessRuleDataService.GetActives())
            {
                allVms.Add(new AccessRuleVM(AccessRuleDataService, accessRule, Access));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeTreeCommand = new Command(ExcludeTree, CanExcludeTree);

            foreach (UserAccessNodeVM item in selectedVms)
            {
                if (item.ParentId == RootNode.Id)
                {
                    RootNode.ChildNodes.Add(item);
                    break;
                }
            }

            CurrentNode = RootNode;
        }