diff --git a/Stars Assistant/Model/StarsDatabase.cs b/Stars Assistant/Model/StarsDatabase.cs index 6426bd3..9f0e990 100644 --- a/Stars Assistant/Model/StarsDatabase.cs +++ b/Stars Assistant/Model/StarsDatabase.cs @@ -20,7 +20,9 @@ public class StarsDatabase(string DbPath) : DbContext #endregion - #region Entities + #region IStarsDatabase Implementation + + public DbContext DbContext => this; /// /// List of all Planets read. diff --git a/Stars Assistant/Program.cs b/Stars Assistant/Program.cs index 4029ab1..4f905f3 100644 --- a/Stars Assistant/Program.cs +++ b/Stars Assistant/Program.cs @@ -1,5 +1,6 @@ using System; using Avalonia; +using Splat; using Microsoft.EntityFrameworkCore; using CsvHelper.Configuration; @@ -19,6 +20,12 @@ sealed class Program [STAThread] public static void Main(string[] args) { + ModeDetector.OverrideModeDetector(Splat.ModeDetection.Mode.Run); + Locator.CurrentMutable.Register( + () => new StarsDatabase("stars.sqlite"), + typeof(StarsDatabase) + ); + __createTestData(); BuildAvaloniaApp() @@ -36,13 +43,13 @@ sealed class Program public static void __createTestData () { - using var db = new StarsDatabase("stars.sqlite"); + using var db = Locator.Current.GetService()!; db.Database.EnsureDeleted(); db.Database.EnsureCreated(); // Note: This sample requires the database to be created before running. - Console.WriteLine($"Database path: {db.DbPath}."); + // Console.WriteLine($"Database path: {db.DbPath}."); Race r = new() { diff --git a/Stars Assistant/Stars Assistant.csproj b/Stars Assistant/Stars Assistant.csproj index e07b684..9e540ba 100644 --- a/Stars Assistant/Stars Assistant.csproj +++ b/Stars Assistant/Stars Assistant.csproj @@ -27,6 +27,7 @@ + diff --git a/Stars Assistant/ViewModels/PlanetViewModel.cs b/Stars Assistant/ViewModels/PlanetViewModel.cs index 1459cbe..b53f45b 100644 --- a/Stars Assistant/ViewModels/PlanetViewModel.cs +++ b/Stars Assistant/ViewModels/PlanetViewModel.cs @@ -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 LoadAll() { - var context = new StarsDatabase("stars.sqlite"); + using var db = Locator.Current.GetService()!; var result = new ObservableCollection(); - 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; } diff --git a/Stars Assistant/Views/MainWindow.axaml b/Stars Assistant/Views/MainWindow.axaml index f09adda..13afb4c 100644 --- a/Stars Assistant/Views/MainWindow.axaml +++ b/Stars Assistant/Views/MainWindow.axaml @@ -19,18 +19,7 @@ - - - - - - - - - - - - + Welcome to Stars Assistant!