private async void SelectedLocations_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { try { SelectedLocations.CollectionChanged -= SelectedLocations_CollectionChanged; if (e.NewItems != null) { foreach (Location newItem in e.NewItems) { SelectedLocations.Add(newItem); await _settingsService.AddLocationAsync(newItem); } } if (e.OldItems != null) { foreach (Location oldtem in e.OldItems) { SelectedLocations.Remove(oldtem); await _settingsService.RemoveLocationAsync(oldtem); } } SelectedLocations.CollectionChanged += SelectedLocations_CollectionChanged; } catch (Exception exeption) { _loggingService?.WriteError(exeption); } }
private async Task SaveDefaultLocationAsync(User user) { if (_settingsService.Settings.Locations.Any()) { return; } var defaultLocation = user.Locations.SingleOrDefault(x => x.Id == user.DefaulLocationId); if (defaultLocation != null) { await _settingsService.AddLocationAsync(defaultLocation); } }