public NewObjectViewModel(ICttObjectTrackingService cttObjectTrackingService, INavigationService navigationService, ISystemTrayService systemTrayService, IMessageBoxService messageBoxService) { _cttObjectTrackingService = cttObjectTrackingService; _navigationService = navigationService; _systemTrayService = systemTrayService; _messageBoxService = messageBoxService; AddObjectCommand = new RelayCommand(() => { if (string.IsNullOrWhiteSpace(ObjectId)) { _messageBoxService.Show("Por favor indique o número do objecto", "Erro"); return; } _systemTrayService.SetProgressIndicator(string.Format("A adicionar: {0}...", ObjectId)); _cttObjectTrackingService.GetCttObjectTrackingStatus(ObjectId, result => { _systemTrayService.HideProgressIndicator(); if (result.Error != null) { _messageBoxService.Show(string.Format("Não foi possível adicionar o objecto \"{0}\"", ObjectId), "Erro"); ScanBarcodeCommand.RaiseCanExecuteChanged(); AddObjectCommand.RaiseCanExecuteChanged(); } else { MessengerInstance.Send <AddObjectMessage>(new AddObjectMessage(_description, result.ETag, result.Data)); _navigationService.GoBack(); ObjectId = null; } }, null); ScanBarcodeCommand.RaiseCanExecuteChanged(); AddObjectCommand.RaiseCanExecuteChanged(); }, () => !IsBusy); ScanBarcodeCommand = new RelayCommand(() => { _navigationService.NavigateTo(new Uri("/View/ScanBarcodePage.xaml", UriKind.Relative)); }, () => !IsBusy); MessengerInstance.Register <ScannedBarcodeMessage>(this, message => { ObjectId = message.ObjectId; }); }
private void RefreshNext(IEnumerator <ObjectDetailsViewModel> enumerator) { if (enumerator.MoveNext()) { var objectModel = enumerator.Current.Model; var objectId = objectModel.ObjectId; var etag = objectModel.ETag; _systemTrayService.SetProgressIndicator(string.Format("A actualizar: {0}...", objectId)); _cttObjectTrackingService.GetCttObjectTrackingStatus(objectId, etag, result => { if (result.Error != null) { _systemTrayService.HideProgressIndicator(); _messageBoxService.Show(string.Format("Não foi possível actualizar o objecto \"{0}\"", objectId), "Erro"); return; } else if (result.StatusCode != System.Net.HttpStatusCode.NotModified) { objectModel.ETag = result.ETag; objectModel.State = result.Data; } RefreshNext(enumerator); }, null); } else { enumerator.Dispose(); _systemTrayService.HideProgressIndicator(); _model.Save(); } }