public AddIssueMobilePlantViewModel(AddIssueMobilePlantDialog view, int? selectedEquipmentId = null) { mGridRefreshTimer.Interval = TimeSpan.FromMilliseconds(500); mGridRefreshTimer.Tick += (sender, eventArgs) => { mGridRefreshTimer.Stop(); ProcessSearchFilter(); }; View = view; mSelectedEquipmentId = selectedEquipmentId; SelectedMobilePlants = new ObservableCollection<QuickMobilePlant>(); LoadData(); OkButtonCommand = new DelegateCommand<object>(OkButtonHandler, CanExecuteCancelButtonHandler); CancelButtonCommand = new DelegateCommand<object>(CancelButtonHandler, CanExecuteOkButtonHandler); SearchCommand = new DelegateCommand<object>(x => ProcessSearchFilter(), x => true); }
private void AddButtonHandler(object parameter) { AddIssueMobilePlantDialog dialog = new AddIssueMobilePlantDialog(); dialog.Show(); dialog.Closed += (s1, e1) => { if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { List<int> ids = (dialog.SelectedEquipments.Select(x => x.Id)).ToList(); CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetMobilePlantsByIdsCompleted += (s2, e2) => { foreach (MobilePlant mobilePlant in e2.Result) { IssueRelatedMobilePlant existingMobilePlant = (from x in mIssue.IssueRelatedMobilePlants where x.MobilePlantId == mobilePlant.Id select x).FirstOrDefault(); if (existingMobilePlant == null) { mIssue.IssueRelatedMobilePlants.Add(new IssueRelatedMobilePlant { IssueId = mIssue.Id, MobilePlantId = mobilePlant.Id, MobilePlant = mobilePlant }); RaisePropertyChanged("IssueRelatedMobilePlants"); } } OnCollectionChanged(); RaiseChangeEvent(); }; cmsWebServiceClient.GetMobilePlantsByIdsAsync(ids); } }; }