sa/Stars Assistant/ViewModels/PlanetViewModel.cs

59 lines
1.6 KiB
C#
Raw Permalink 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-24 20:32:13 +00:00
private readonly Planet Planet;
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
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;
// ### TESTING CODE ###
2024-09-24 20:32:13 +00:00
public static ObservableCollection<PlayerPlanetViewModel> LoadAll()
2024-09-23 20:40:18 +00:00
{
using var db = Locator.Current.GetService<StarsDatabase>()!;
2024-09-24 20:32:13 +00:00
var result = new ObservableCollection<PlayerPlanetViewModel>();
2024-09-23 20:40:18 +00:00
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
2024-09-24 20:32:13 +00:00
// foreach (Planet planet in db.Planet.Where(p => p.Name == "Saddam").ToList())
2024-09-23 20:40:18 +00:00
{
2024-09-24 20:32:13 +00:00
var vm = new PlayerPlanetViewModel(planet);
2024-09-23 20:40:18 +00:00
result.Add(vm);
}
return result;
}
}