sa/Stars Assistant/ViewModels/PlanetViewModel.cs
2024-09-24 22:32:13 +02:00

59 lines
1.6 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
{
private readonly Planet Planet;
public PlanetViewModel(Planet planet)
{
Planet = planet;
this.WhenActivated((CompositeDisposable disposables) =>
{
// /* handle activation */
// Disposable
// .Create(() => { /* handle deactivation */ })
// .DisposeWith(disposables);
});
}
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<PlayerPlanetViewModel> LoadAll()
{
using var db = Locator.Current.GetService<StarsDatabase>()!;
var result = new ObservableCollection<PlayerPlanetViewModel>();
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
// foreach (Planet planet in db.Planet.Where(p => p.Name == "Saddam").ToList())
{
var vm = new PlayerPlanetViewModel(planet);
result.Add(vm);
}
return result;
}
}