diff --git a/critterfolio/CritterFolio/CritterFolio/Pages/FamilyTreePage.axaml.cs b/critterfolio/CritterFolio/CritterFolio/Pages/FamilyTreePage.axaml.cs index e42d227..95cedb5 100644 --- a/critterfolio/CritterFolio/CritterFolio/Pages/FamilyTreePage.axaml.cs +++ b/critterfolio/CritterFolio/CritterFolio/Pages/FamilyTreePage.axaml.cs @@ -52,8 +52,11 @@ public partial class FamilyTreePage : Page { var border = new Border { - Classes = { "critter-card child" }, - Child = new TextBlock {Text = $"[Child]\n{child.Name}"} + Classes = { "critter-card", "child"}, + Child = new TextBlock + { + Text = $"[Child]\n{child.Name}" + } }; ChildStack.Children.Add(border); diff --git a/critterfolio/CritterFolio/CritterFolio/Pages/TestPage.axaml b/critterfolio/CritterFolio/CritterFolio/Pages/TestPage.axaml index b58abd0..6b9d76f 100644 --- a/critterfolio/CritterFolio/CritterFolio/Pages/TestPage.axaml +++ b/critterfolio/CritterFolio/CritterFolio/Pages/TestPage.axaml @@ -6,12 +6,11 @@ x:Class="CritterFolio.Pages.TestPage"> - - - - + + + diff --git a/critterfolio/CritterFolio/CritterFolio/Pages/TestPage.axaml.cs b/critterfolio/CritterFolio/CritterFolio/Pages/TestPage.axaml.cs index 4666d39..b398f27 100644 --- a/critterfolio/CritterFolio/CritterFolio/Pages/TestPage.axaml.cs +++ b/critterfolio/CritterFolio/CritterFolio/Pages/TestPage.axaml.cs @@ -5,6 +5,7 @@ using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Platform.Storage; +using CritterFolio.DataModels; using CritterFolio.Services; namespace CritterFolio.Pages; @@ -17,11 +18,57 @@ public partial class TestPage : Page { InitializeComponent(); + TestDataButton.Click += TestDataButtonClicked; ClearDbButton.Click += ClearDbButtonClicked; - ReInitButton.Click += ReInitButtonClicked; OpenLogButton.Click += OpenLogButtonClicked; } + private async void TestDataButtonClicked(object? sender, RoutedEventArgs e) + { + var result = await DialogHelper.ShowConfirmationDialog("Are you sure you want to insert test data into the database?"); + if (!result) return; + + try + { + var toriel = new Critter + { + Name = "Toriel", + DateOfBirth = new DateTime(2018, 07, 04), + Gender = Gender.Female, + Notes = "The very first goat on the farm, found on July 4th 2019 abandoned on the roadside. Named after Toriel from Undertale.", + }; + await DatabaseService.AddCritter(toriel); + + var polities = new Critter() + { + Name = "Polities", + DateOfBirth = new DateTime(2024, 01, 01), + Gender = Gender.Male, + Notes = "The first pure bred Nigerian Dwarf purchased on the farm. Named after Polities from Homer's Odyssey.", + }; + await DatabaseService.AddCritter(polities); + + var torielId = DatabaseService.GetCritter("Toriel").Id; + var poliId = DatabaseService.GetCritter("Polities").Id; + + var jessie = new Critter + { + Name = "Jessie", + DateOfBirth = new DateTime(2025, 04, 05), + Gender = Gender.Male, + Notes = "Polities' first son. Named after Jessie from The Last Of Us.", + + }; + await DatabaseService.AddCritter(jessie); + + } + catch (Exception exception) + { + await DialogHelper.ShowMessage($"[ERROR] {exception.Message}"); + Logger.LogToFile($"[ERROR] {exception.Message}"); + } + } + private void OpenLogButtonClicked(object? sender, RoutedEventArgs args) { Sys.Navigation?.PushPage(new LogPage()); @@ -30,6 +77,9 @@ public partial class TestPage : Page private async void ClearDbButtonClicked(object? sender, RoutedEventArgs args) { + var result = await DialogHelper.ShowConfirmationDialog("Are you sure you want to clear the database?"); + if (!result) return; + try { await DatabaseService.ClearAllTables(); @@ -40,11 +90,7 @@ public partial class TestPage : Page Console.WriteLine(ex.ToString()); } } - - private async void ReInitButtonClicked(object? sender, RoutedEventArgs e) - { - await DatabaseService.Init(); - } + public override void Refresh() { @@ -55,6 +101,8 @@ public partial class TestPage : Page protected override void ClearConnections() { - + // TestDataButton.Click -= TestDataButtonClicked; + // ClearDbButton.Click -= ClearDbButtonClicked; + // OpenLogButton.Click -= OpenLogButtonClicked; } } \ No newline at end of file diff --git a/critterfolio/CritterFolio/CritterFolio/Services/DatabaseService.cs b/critterfolio/CritterFolio/CritterFolio/Services/DatabaseService.cs index c9ebba3..814a640 100644 --- a/critterfolio/CritterFolio/CritterFolio/Services/DatabaseService.cs +++ b/critterfolio/CritterFolio/CritterFolio/Services/DatabaseService.cs @@ -78,6 +78,14 @@ public static class DatabaseService await Init(); return _db?.GetAsync(id).Result; } + + public static async Task GetCritter(string name) + { + await Init(); + return await _db?.Table() + .Where(c => c.Name == name) + .FirstOrDefaultAsync()!; + } #endregion