Dependency Injection, frist UI Reworks

This commit is contained in:
2024-09-11 20:04:20 +02:00
parent a9763be8d2
commit fa82a4fbb3
6 changed files with 25 additions and 31 deletions

View File

@ -1,15 +1,16 @@
using System.Collections.ObjectModel;
using Microsoft.EntityFrameworkCore;
using StarsAssistant.Model;
using Splat;
namespace StarsAssistant.ViewModels;
public partial class PlanetViewModel(Planet planet) : ViewModelBase
{
public static ObservableCollection<PlanetViewModel> LoadAll() {
var context = new StarsDatabase("stars.sqlite");
using var db = Locator.Current.GetService<StarsDatabase>()!;
var result = new ObservableCollection<PlanetViewModel>();
foreach (Planet planet in context.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
foreach (Planet planet in db.Planet.Where(p => p.OwnerId == "Atlantis").ToList())
{
var vm = new PlanetViewModel(planet);
result.Add(vm);
@ -24,4 +25,12 @@ public partial class PlanetViewModel(Planet planet) : ViewModelBase
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;
}