public AddIssueElectricalEquipmentViewModel(AddIssueElectricalEquipmentDialog view, int? selectedEquipmentId = null)
        {
            mGridRefreshTimer.Interval = TimeSpan.FromMilliseconds(500);
            mGridRefreshTimer.Tick += (sender, eventArgs) => { mGridRefreshTimer.Stop(); ProcessSearchFilter(); };

            View = view;
            mSelectedEquipmentId = selectedEquipmentId;
            SelectedElectricalEquipments = new List<QuickElectrical>();

            LoadData();

            OkButtonCommand = new DelegateCommand<object>(OkButtonHandler, CanExecuteOkButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CanelButtonHandler, CanExecuteOkButtonHandler);
            SearchCommand = new DelegateCommand<object>(x => ProcessSearchFilter(), x => true);
        }
        private void AddElectricalEquipmentButtonHandler(object parameter)
        {
            AddIssueElectricalEquipmentDialog addIssueElectricalEquipmentDialog = new AddIssueElectricalEquipmentDialog();
            addIssueElectricalEquipmentDialog.Show();
            addIssueElectricalEquipmentDialog.Closed +=
                (s1, e1) =>
                {
                    if (addIssueElectricalEquipmentDialog.DialogResult.HasValue && addIssueElectricalEquipmentDialog.DialogResult.Value)
                    {
                        List<QuickElectrical> equipmentsToAdd = addIssueElectricalEquipmentDialog.SelectedEquipments.ToList();

                        List<int> ids = (from x in equipmentsToAdd select x.Id).ToList();

                        CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
                        cmsWebServiceClient.GetElectricalEquipmentsByIdsCompleted +=
                            (s2, e2) =>
                            {
                                foreach (ElectricalEquipment electricalEquipment in e2.Result)
                                {
                                    IssueRelatedElectricalEquipment existingEquipments = (from x in mIssue.IssueRelatedElectricalEquipments where x.ElectricalEquipmentId == electricalEquipment.Id select x).FirstOrDefault();
                                    if (existingEquipments == null)
                                    {
                                        mIssue.IssueRelatedElectricalEquipments.Add(new IssueRelatedElectricalEquipment
                                                                                        {
                                                                                            IssueId = mIssue.Id,
                                                                                            ElectricalEquipmentId = electricalEquipment.Id,
                                                                                            ElectricalEquipment = electricalEquipment
                                                                                        });
                                    }
                                }

                                RaiseChangeEvent();

                                RaisePropertyChanged("IssueRelatedElectricals");
                                OnCollectionChanged();
                            };

                        cmsWebServiceClient.GetElectricalEquipmentsByIdsAsync(ids);
                    }
                };
        }
        private void MoveComponentHandler(object parameter)
        {
            if (SelectedComponent != null)
            {
                AddIssueElectricalEquipmentDialog dialog = new AddIssueElectricalEquipmentDialog("Select Destination Tag", true, SelectedComponent.ElectricalEquipmentId);
                dialog.Show();

                //Select the component as user might have changed the component type
                //and this needs to reload the component type properties
                dialog.Closed += (s1, e1) =>
                                     {
                                         if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                                         {
                                             if (dialog.SelectedEquipment != null)
                                             {
                                                 //THE MOVE (parent  id changed)
                                                 SelectedComponent.ElectricalEquipmentId = dialog.SelectedEquipment.Id;

                                                 //need to CLONE due to the line "RaisePropertyChanged("Components");"
                                                 MovedComponent = CloneComponent(SelectedComponent);
                                                 MovedComponent.ElectricalEquipment = new ElectricalEquipment
                                                                                          {
                                                                                              Id = dialog.SelectedEquipment.Id,
                                                                                              Name = dialog.SelectedEquipment.Name
                                                                                          };

                                                 //remove
                                                 mElectricalEquipment.ElectricalEquipmentComponents.Remove(SelectedComponent);
                                                 RaiseChangeEvent();
                                                 OnCollectionChanged();
                                                 mSelectedComponent = null;

                                                 RaisePropertyChanged("Components");
                                             }
                                         }
                                     };
            }
        }