예제 #1
0
        public AccessRulePositionsVM(AccessRuleVM accessRule, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentAccessRule = accessRule;
            AccessRuleDataService = new AccessRuleDataService(UnitOfWork);
            AccessRuleDataService.PositionAdded += OnPositionAdded;
            AccessRuleDataService.PositionRemoved += OnPositionRemoved;
            PositionDataService = new PositionDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<PositionAccessRuleVM>();
            foreach (var accessRulePosition in AccessRuleDataService.GetPositions(accessRule.Id))
            {
                selectedVms.Add(new PositionAccessRuleVM(accessRulePosition, Access, RelationDirection.Reverse));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<PositionVM>();
            foreach (var position in PositionDataService.GetActives())
            {
                allVms.Add(new PositionVM(position, Access,PositionDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include,CanInclude);
            ExcludeCommand = new Command(Exclude,CanExclude);
        }
예제 #2
0
        public UserPositionsVM(UserVM user, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentUser = user;
            UserDataService = new UserDataService(UnitOfWork);
            PositionDataService = new PositionDataService(UnitOfWork);
            AccessRuleDataService = new AccessRuleDataService(UnitOfWork);
            UserDataService.PositionAdded += OnPositionAdded;
            UserDataService.PositionRemoved += OnPositionRemoved;


            var selectedVms = new ObservableCollection<UserPositionVM>();
            foreach (var userPosition in UserDataService.GetPositions(user.Id))
            {
                selectedVms.Add(new UserPositionVM(userPosition, Access, RelationDirection.Straight));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<PositionVM>();
            foreach (var position in PositionDataService.GetActives(SoheilEntityType.Users, CurrentUser.Id))
            {
                allVms.Add(new PositionVM(position, Access, PositionDataService));
            }
            AllItems = new ListCollectionView(allVms);

            //AllItems = new ListCollectionView(PositionDataService.GetActives());
            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
        }
        public OrganizationChartPositionsVM(OrganizationChartVM organizationChart, AccessType access):base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentOrganizationChart = organizationChart;
            OrganizationChartDataService = new OrganizationChartDataService(UnitOfWork);
            OrganizationChartDataService.PositionAdded += OnPositionAdded;
            OrganizationChartDataService.PositionRemoved += OnPositionRemoved;
            PositionDataService = new PositionDataService(UnitOfWork);
            OrganizationChartPositionDataService = new OrganizationChartPositionDataService(UnitOfWork);

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

            var selectedVms = new ObservableCollection<OrganizationChartPositionVM>();
            foreach (var organizationChartPosition in OrganizationChartDataService.GetPositions(organizationChart.Id))
            {
                selectedVms.Add(new OrganizationChartPositionVM(organizationChartPosition, Access, OrganizationChartPositionDataService));
            }

            var allVms = new ObservableCollection<PositionVM>();
            foreach (var position in PositionDataService.GetActives(SoheilEntityType.OrganizationCharts, CurrentOrganizationChart.Id))
            {
                allVms.Add(new PositionVM(position, Access, PositionDataService));
            }
            AllItems = new ListCollectionView(allVms);

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


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

            CurrentNode = RootNode;
        }