diff --git a/critterfolio/CritterFolio/CritterFolio/Controls/DocumentItem.axaml b/critterfolio/CritterFolio/CritterFolio/Controls/DocumentItem.axaml
new file mode 100644
index 0000000..6c5353b
--- /dev/null
+++ b/critterfolio/CritterFolio/CritterFolio/Controls/DocumentItem.axaml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/critterfolio/CritterFolio/CritterFolio/Controls/DocumentItem.axaml.cs b/critterfolio/CritterFolio/CritterFolio/Controls/DocumentItem.axaml.cs
new file mode 100644
index 0000000..c78ef5a
--- /dev/null
+++ b/critterfolio/CritterFolio/CritterFolio/Controls/DocumentItem.axaml.cs
@@ -0,0 +1,73 @@
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Markup.Xaml;
+using CritterFolio.DataModels;
+using CritterFolio.Services;
+
+namespace CritterFolio.Controls;
+
+public partial class DocumentItem : UserControl
+{
+ private Document? _document;
+
+ public DocumentItem()
+ {
+ InitializeComponent();
+ }
+
+ public void Init(Document document)
+ {
+ _document = document;
+
+ NameLabel.Content = document.Name;
+
+ ViewButton.Click += ViewButtonOnClick;
+ DeleteButton.Click += DeleteButtonOnClick;
+ }
+
+ private async void DeleteButtonOnClick(object? sender, RoutedEventArgs e)
+ {
+ if (_document is null) return;
+ if (File.Exists(_document.Path))
+ {
+ var result = await DialogHelper.ShowConfirmationDialog("Are you sure you want to delete this document?");
+ if (result) File.Delete(_document.Path);
+ }
+ else
+ {
+ await DialogHelper.ShowMessage("Document does not exist");
+ }
+ }
+
+ private async void ViewButtonOnClick(object? sender, RoutedEventArgs e)
+ {
+ if (_document is null) return;
+ if (File.Exists(_document.Path))
+ {
+ var launcher = TopLevel.GetTopLevel(this)?.Launcher;
+
+ if (launcher != null)
+ {
+ var launchResult = await launcher.LaunchUriAsync(new Uri(_document.Path));
+ if (launchResult) return;
+ await DialogHelper.ShowMessage($"Couldn't launch the file: {_document.Path}");
+ Logger.LogToFile($"[ERROR] Couldn't launch the file: {_document.Path}");
+ }
+ else
+ {
+ await DialogHelper.ShowMessage("Launcher was null for some reason. Please report this to the developer.");
+ Logger.LogToFile("Launcher was null for some reason. Please report this to the developer.");
+ }
+
+ }
+ else
+ {
+ await DialogHelper.ShowMessage("Document does not exist");
+ Logger.LogToFile("Document does not exist");
+ }
+ }
+}
\ No newline at end of file
diff --git a/critterfolio/CritterFolio/CritterFolio/DataModels/Document.cs b/critterfolio/CritterFolio/CritterFolio/DataModels/Document.cs
index 320d4f2..0b1c4c1 100644
--- a/critterfolio/CritterFolio/CritterFolio/DataModels/Document.cs
+++ b/critterfolio/CritterFolio/CritterFolio/DataModels/Document.cs
@@ -9,5 +9,6 @@ public class Document
public int Id { get; set; }
public int CritterId { get; set; }
public string Name { get; set; } = "Document";
+ public string Path { get; set; } = "";
public string Description { get; set; } = "A Document";
}
\ No newline at end of file
diff --git a/critterfolio/CritterFolio/CritterFolio/Pages/CritterPage.axaml b/critterfolio/CritterFolio/CritterFolio/Pages/CritterPage.axaml
index 6ef1bbf..dcecb47 100644
--- a/critterfolio/CritterFolio/CritterFolio/Pages/CritterPage.axaml
+++ b/critterfolio/CritterFolio/CritterFolio/Pages/CritterPage.axaml
@@ -6,11 +6,17 @@
x:Class="CritterFolio.Pages.CritterPage">
+
+
+
+
+
+
+
-
-
+
@@ -32,10 +38,13 @@
-
-
-
-
+
+
+
+
+
+
+
diff --git a/critterfolio/CritterFolio/CritterFolio/Pages/CritterPage.axaml.cs b/critterfolio/CritterFolio/CritterFolio/Pages/CritterPage.axaml.cs
index 2b20dce..8240795 100644
--- a/critterfolio/CritterFolio/CritterFolio/Pages/CritterPage.axaml.cs
+++ b/critterfolio/CritterFolio/CritterFolio/Pages/CritterPage.axaml.cs
@@ -278,11 +278,7 @@ public partial class CritterPage : Page
try
{
-
await using var stream = await file.OpenReadAsync();
- // using var streamReader = new StreamReader(stream);
- // var fileContent = await streamReader.ReadToEndAsync();
-
var bmp = new Bitmap(stream);
var path = Path.Combine(Sys.UserDataPath, "ImageCache", $"{_critter.Id}-{_critter.Name}.jpg");
bmp.Save(path, 5);
diff --git a/critterfolio/CritterFolio/CritterFolio/Services/DatabaseService.cs b/critterfolio/CritterFolio/CritterFolio/Services/DatabaseService.cs
index 0c7d9d5..c9ebba3 100644
--- a/critterfolio/CritterFolio/CritterFolio/Services/DatabaseService.cs
+++ b/critterfolio/CritterFolio/CritterFolio/Services/DatabaseService.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Threading.Tasks;
using CritterFolio.DataModels;
using Microsoft.VisualBasic.FileIO;
@@ -79,4 +80,53 @@ public static class DatabaseService
}
#endregion
+
+ #region Document operations
+
+ public static async Task AddDocument(Document document)
+ {
+ await Init();
+ var result = await _db?.InsertAsync(document)!;
+ return !(result <= 0);
+ }
+
+ public static async Task UpdateDocument(Document document)
+ {
+ await Init();
+ return await _db?.UpdateAsync(document)! != 0;
+ }
+
+ public static async Task DeleteDocument(Document document)
+ {
+ await Init();
+ return await _db?.DeleteAsync(document)! != 0;
+ }
+
+ public static async Task DeleteDocument(int id)
+ {
+ await Init();
+ return await _db?.DeleteAsync(id)! != 0;
+ }
+
+ public static async Task> GetAllDocuments()
+ {
+ await Init();
+ var result = await _db?.Table().ToListAsync()!;
+ return result ?? [];
+ }
+
+ public static async Task> GetAllDocumentsForCritter(int critterId)
+ {
+ await Init();
+ var result = await _db?.Table().Where(d => d.CritterId == critterId).ToListAsync()!;
+ return result ?? [];
+ }
+
+ public static async Task GetDocument(int id)
+ {
+ await Init();
+ return _db?.GetAsync(id).Result;
+ }
+
+ #endregion
}
\ No newline at end of file