sa/Stars Assistant/ViewModels/PlanetViewModel.cs

53 lines
1.5 KiB
C#
Raw Normal View History

using System.Collections.ObjectModel;
2024-09-23 20:40:18 +00:00
using System.Reactive.Disposables;
using Microsoft.EntityFrameworkCore;
2024-09-23 20:40:18 +00:00
using ReactiveUI;
2024-08-15 19:46:43 +00:00
using StarsAssistant.Model;
2024-09-11 18:04:20 +00:00
using Splat;
2024-08-15 19:46:43 +00:00
namespace StarsAssistant.ViewModels;
2024-09-23 20:40:18 +00:00
public partial class PlanetViewModel : ViewModelBase
{
2024-09-23 20:40:18 +00:00
public PlanetViewModel(Planet planet)
{
2024-09-23 20:40:18 +00:00
Planet = planet;
this.WhenActivated((CompositeDisposable disposables) =>
{
2024-09-23 20:40:18 +00:00
// /* handle activation */
// Disposable
// .Create(() => { /* handle deactivation */ })
// .DisposeWith(disposables);
});
}
2024-09-23 20:40:18 +00:00
private readonly Planet Planet;
2024-09-23 20:40:18 +00:00
public string Name => Planet.Name;
2024-09-23 20:40:18 +00:00
public string Owner => Planet.OwnerId ?? String.Empty;
2024-09-23 20:40:18 +00:00
public int Value => Planet.Value ?? 0;
2024-09-11 18:04:20 +00:00
2024-09-23 20:40:18 +00:00
public int Population => Planet.Population ?? 0;
2024-09-11 18:04:20 +00:00
2024-09-23 20:40:18 +00:00
public int SurfaceIronium => Planet.SurfaceIronium ?? 0;
2024-09-11 18:04:20 +00:00
2024-09-23 20:40:18 +00:00
public int SurfaceBoranium => Planet.SurfaceBoranium ?? 0;
2024-09-11 18:04:20 +00:00
2024-09-23 20:40:18 +00:00
public int SurfaceGermanium => Planet.SurfaceGermanium ?? 0;
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;
}
}