using System.Collections.ObjectModel; using System.Reactive.Disposables; using Microsoft.EntityFrameworkCore; using ReactiveUI; using StarsAssistant.Model; using Splat; namespace StarsAssistant.ViewModels; public partial class PlanetViewModel : ViewModelBase { public PlanetViewModel(Planet planet) { Planet = planet; this.WhenActivated((CompositeDisposable disposables) => { // /* handle activation */ // Disposable // .Create(() => { /* handle deactivation */ }) // .DisposeWith(disposables); }); } private readonly Planet Planet; public string Name => Planet.Name; public string Owner => Planet.OwnerId ?? String.Empty; public int Value => Planet.Value ?? 0; public int Population => Planet.Population ?? 0; public int SurfaceIronium => Planet.SurfaceIronium ?? 0; public int SurfaceBoranium => Planet.SurfaceBoranium ?? 0; public int SurfaceGermanium => Planet.SurfaceGermanium ?? 0; public static ObservableCollection LoadAll() { using var db = Locator.Current.GetService()!; var result = new ObservableCollection(); foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList()) { var vm = new PlanetViewModel(planet); result.Add(vm); } return result; } }