public ControlSystemAttachmentsViewModel(ControlSystem controlSystem, ControlSystemAttachmentsControl view)
        {
            CompositionInitializer.SatisfyImports(this);

            View = view;

            AddAttachmentCommand = new DelegateCommand<object>(AddFileHandler, CanAdd);
            RemoveAttachmentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            ExportButton = new DelegateCommand<object>(ExportButtonHandler, x => true);

            mControlSystem = controlSystem;

            Attachments = new ObservableCollection<ControlSystemAttachment>();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAttachmentTypesCompleted += cmsWebServiceClient_GetAttachmentTypesCompleted;
            cmsWebServiceClient.GetAttachmentTypesAsync();
        }
        private void LoadData()
        {
            //Testing
            mControlSystemTestingPropertiesControl = new ControlSystemTestingPropertiesControl(ControlSystem);
            View.TestingTab.Content = mControlSystemTestingPropertiesControl;

            //Issues
            mControlSystemRelatedIssuesView = new ControlSystemRelatedIssuesView(ControlSystem);
            mControlSystemRelatedIssuesView.CollectionChanged += count =>
            {
                ControlSystem.GeneralEquipmentRelatedItemsCount.Issues = count;
                SetTabHeadersText();
            };
            View.RelatedIssuesTab.Content = mControlSystemRelatedIssuesView;

            //INTERLOCK
            mControlSystemInterlocksView = new ControlSystemInterlocksView(ControlSystem);
            mControlSystemInterlocksView.CollectionChanged += count =>
            {
                ControlSystem.GeneralEquipmentRelatedItemsCount.Interlocks = count;
                SetTabHeadersText();
            };
            View.InterlocksTab.Content = mControlSystemInterlocksView;

            //AREAS
            Areas = new List<Area>(from x in CMS.Cache.Areas where x.IsActive && x.SiteId == CMS.AppSetting.DefaultSiteId select x);

            //Components
            mComponentsControl = new ControlSystemComponentsControl(ControlSystem);
            mComponentsLoaded = true;
            mComponentsControl.CollectionChanged += count =>
            {
                ControlSystem.GeneralEquipmentRelatedItemsCount.PropertyOrComponents = count;

                SetTabHeadersText();
            };
            View.ComponentsTab.Content = mComponentsControl;

            //Attachments
            mControlSystemAttachmentsControl = new ControlSystemAttachmentsControl(ControlSystem);
            mControlSystemAttachmentsControl.ModelLoaded += () =>
            {
                mAttachmentsLoaded = true;
                CheckAllLoaded();
            };
            mControlSystemAttachmentsControl.CollectionChanged += count =>
            {
                ControlSystem.GeneralEquipmentRelatedItemsCount.Attachments = count;
                SetTabHeadersText();
            };
            View.AttachmentsTab.Content = mControlSystemAttachmentsControl;

            mControlSystemDocumentsView = new ControlSystemDocumentsView(ControlSystem);

            mControlSystemDocumentsView.ControlLoaded += mDocumentsControl_ControlLoaded;
            RoutedEventHandler docsloaded = null;

            docsloaded = (s1, e1) =>
            {
                //This will hook up change events on all controls
                Utils.SetUpChangeEvents((UIElement) View.DocumentsTab.Content, EventAggregator, ControlSystem);
                View.DocumentsTab.Loaded -= docsloaded;
            };

            View.DocumentsTab.Loaded += docsloaded;

            var pidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode);
            var specificationDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode);
            var getQuickControlSystemTypesTask = DatabaseLoader.GetQuickControlSystemTypes();
            var getUpperEquipmentsTask = DatabaseLoader.GetUpperEquipments();
            var getGraphicsTask = DatabaseLoader.GetGraphics();
            var getControlSystemComponentTypesTask = DatabaseLoader.GetControlSystemComponentTypes();

            var tasks = new List<Task>();
            tasks.Add(pidDocumentsTask);
            tasks.Add(specificationDocumentsTask);
            tasks.Add(getQuickControlSystemTypesTask);
            tasks.Add(getGraphicsTask);
            tasks.Add(getControlSystemComponentTypesTask);

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    PandIDDocuments = pidDocumentsTask.Result;
                    SpecificationDocuments = specificationDocumentsTask.Result;

                    mAllUpperEquipments = getUpperEquipmentsTask.Result;
                    mAllUpperEquipments.Insert(0, new UpperEquipment {Name = CMS.Constants.UpperEquipmentNullName});
                    UpperEquipments = mAllUpperEquipments;

                    Graphics = getGraphicsTask.Result;

                    ControlSystemTypes = getQuickControlSystemTypesTask.Result;
                    RaisePropertyChanged("ControlSystemTypes");
                    RaisePropertyChanged("SelectedControlSystemType");

                    //ControlSystemComponentType
                    ControlSystemComponentTypes = getControlSystemComponentTypesTask.Result;
                    //SelectedControlSystemComponentType = ??
                    RaisePropertyChanged("SelectedControlSystemComponentType");

                    RaisePropertyChanged("PandIDDocuments");
                    RaisePropertyChanged("SelectedPAndIDDocument");

                    RaisePropertyChanged("SpecificationDocuments");
                    RaisePropertyChanged("SelectedSpecificationDocument");

                    RaiseLoaded();
                });
            });

            View.RevisionHistory.LoadRevisionHistory(CommonUtils.TabId.Control, ControlSystem.Id);

            RaisePropertyChanged("TuningParameters");
        }