sa/Stars Assistant/ViewModels/PlanetViewModel.cs

57 lines
1.5 KiB
C#

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;
// ### TESTING CODE ###
public static ObservableCollection<PlanetViewModel> LoadAll()
{
using var db = Locator.Current.GetService<StarsDatabase>()!;
var result = new ObservableCollection<PlanetViewModel>();
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
{
var vm = new PlanetViewModel(planet);
result.Add(vm);
}
return result;
}
}