public async void Save() { if (string.IsNullOrWhiteSpace(SelectedSource.Id)) { await _progressService.ShowMessageAsync(Resources.SettingsViewModel_SavingSource, Resources.SettingsViewModel_SourceMissingId); return; } if (string.IsNullOrWhiteSpace(SelectedSource.Value)) { await _progressService.ShowMessageAsync(Resources.SettingsViewModel_SavingSource, Resources.SettingsViewModel_SourceMissingValue); return; } await _progressService.StartLoading(Resources.SettingsViewModel_SavingSourceLoading); try { if (_isNewItem) { await _packageService.AddSource(SelectedSource); _isNewItem = false; Sources.Add(SelectedSource); NotifyOfPropertyChange(nameof(CanRemove)); } else { await _packageService.UpdateSource(_originalId, SelectedSource); } _originalId = SelectedSource?.Id; await _eventAggregator.PublishOnUIThreadAsync(new SourcesUpdatedMessage()); } catch (UnauthorizedAccessException) { await _progressService.ShowMessageAsync( Resources.General_UnauthorisedException_Title, Resources.General_UnauthorisedException_Description); } finally { await _progressService.StopLoading(); } }
public async Task Save() { if (string.IsNullOrWhiteSpace(DraftSource.Id)) { await _dialogService.ShowMessageAsync(L(nameof(Resources.SettingsViewModel_SavingSource)), L(nameof(Resources.SettingsViewModel_SourceMissingId))); return; } if (string.IsNullOrWhiteSpace(DraftSource.Value)) { await _dialogService.ShowMessageAsync(L(nameof(Resources.SettingsViewModel_SavingSource)), L(nameof(Resources.SettingsViewModel_SourceMissingValue))); return; } await _progressService.StartLoading(L(nameof(Resources.SettingsViewModel_SavingSourceLoading))); try { if (_isNewItem) { if (DraftSource.Id == ChocolateyLicensedSourceId) { await _progressService.StopLoading(); await _dialogService.ShowMessageAsync(L(nameof(Resources.SettingsViewModel_SavingSource)), L(nameof(Resources.SettingsViewModel_InvalidSourceId))); return; } await _chocolateyService.AddSource(DraftSource); _isNewItem = false; Sources.Add(DraftSource); NotifyOfPropertyChange(nameof(CanRemove)); } else { if (DraftSource.Id == ChocolateyLicensedSourceId) { if (DraftSource.Disabled) { await _chocolateyService.DisableSource(DraftSource.Id); } else { await _chocolateyService.EnableSource(DraftSource.Id); } } else { await _chocolateyService.UpdateSource(_originalId, DraftSource); } Sources[Sources.IndexOf(SelectedSource)] = DraftSource; } _originalId = DraftSource?.Id; await _eventAggregator.PublishOnUIThreadAsync(new SourcesUpdatedMessage()); } catch (UnauthorizedAccessException) { await _dialogService.ShowMessageAsync( L(nameof(Resources.General_UnauthorisedException_Title)), L(nameof(Resources.General_UnauthorisedException_Description))); } finally { SelectedSource = null; await _progressService.StopLoading(); } }