public PositionOrganizationChartsVM(PositionVM position, AccessType access)
            : base(access)
        {
            UnitOfWork = new SoheilEdmContext();
            CurrentPosition = position;
            PositionDataService = new PositionDataService(UnitOfWork);
            PositionDataService.OrganizationChartAdded += OnOrganizationChartAdded;
            PositionDataService.OrganizationChartRemoved += OnOrganizationChartRemoved;
            OrganizationChartDataService = new OrganizationChartDataService(UnitOfWork);
            OrganizationChartPositionDataService = new OrganizationChartPositionDataService(UnitOfWork);

            var selectedVms = new ObservableCollection<OrganizationChartPositionVM>();
            foreach (var positionOrganizationChart in PositionDataService.GetOrganizationCharts(position.Id))
            {
                selectedVms.Add(new OrganizationChartPositionVM(positionOrganizationChart, Access, OrganizationChartPositionDataService));
            }
            SelectedItems = new ListCollectionView(selectedVms);

            var allVms = new ObservableCollection<OrganizationChartVM>();
            foreach (var organizationChart in OrganizationChartDataService.GetActives())
            {
                allVms.Add(new OrganizationChartVM(organizationChart, Access, OrganizationChartDataService));
            }
            AllItems = new ListCollectionView(allVms);

            IncludeCommand = new Command(Include, CanInclude);
            ExcludeCommand = new Command(Exclude, CanExclude);
            
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductVM"/> class from the model.
 /// </summary>
 /// <param name="entity">The model.</param>
 /// <param name="access"></param>
 /// <param name="dataService"></param>
 public OrganizationChartPositionVM(OrganizationChart_Position entity, AccessType access, OrganizationChartPositionDataService dataService):base(access)
 {
     _model = entity;
     InitializeData(dataService);
     OrganizationChartId = entity.OrganizationChart.Id;
     PositionId = entity.Position.Id;
     ParentId = entity.Parent == null? -1: entity.Parent.Id;
     Title = entity.Position.Name;
     foreach (var child in entity.Children)
     {
         ChildNodes.Add(new OrganizationChartPositionVM(child, Access,dataService));
     }
     
 }
        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;
        }
 private void InitializeData(OrganizationChartPositionDataService dataService)
 {
     DataService = dataService;
     SaveCommand = new Command(Save, CanSave);
 }
         /// <summary>
 /// Initializes a new instance of the <see cref="ProductGroupVM"/> class initialized with default values.
 /// </summary>
 public OrganizationChartPositionVM(AccessType access, OrganizationChartPositionDataService dataService):base(access)
 {
     InitializeData(dataService);
     _model = new OrganizationChart_Position();
 }