sa/Stars Assistant/ViewModels/PlanetViewModel.cs

37 lines
1.1 KiB
C#
Raw Normal View History

using System.Collections.ObjectModel;
using Microsoft.EntityFrameworkCore;
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;
public partial class PlanetViewModel(Planet planet) : ViewModelBase
{
public static ObservableCollection<PlanetViewModel> LoadAll() {
2024-09-11 18:04:20 +00:00
using var db = Locator.Current.GetService<StarsDatabase>()!;
var result = new ObservableCollection<PlanetViewModel>();
2024-09-11 18:04:20 +00:00
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
{
var vm = new PlanetViewModel(planet);
result.Add(vm);
}
return result;
}
private readonly Planet planet = planet;
public string Name => planet.Name;
public string Owner => planet.OwnerId ?? String.Empty;
public int Value => planet.Value ?? 0;
2024-09-11 18:04:20 +00:00
public int Population => planet.Population ?? 0;
public int SurfaceIronium => planet.SurfaceIronium ?? 0;
public int SurfaceBoranium => planet.SurfaceBoranium ?? 0;
public int SurfaceGermanium => planet.SurfaceGermanium ?? 0;
}