diff --git a/AutoCat/Pages/HistoryPage.axaml b/AutoCat/Pages/HistoryPage.axaml index 4e11d11..b93e88b 100644 --- a/AutoCat/Pages/HistoryPage.axaml +++ b/AutoCat/Pages/HistoryPage.axaml @@ -5,6 +5,7 @@ xmlns:pages="clr-namespace:AutoCat.Pages" xmlns:utils="using:AutoCat.Utils" xmlns:vm="using:AutoCat.ViewModels" + xmlns:models="using:AutoCatCore.Model" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="AutoCat.Pages.HistoryPage" x:DataType="vm:HistoryViewModel" @@ -19,6 +20,18 @@ + + + + + + + + + + + + + diff --git a/AutoCat/ViewModels/HistoryViewModel.cs b/AutoCat/ViewModels/HistoryViewModel.cs index 48a0d55..ce17623 100644 --- a/AutoCat/ViewModels/HistoryViewModel.cs +++ b/AutoCat/ViewModels/HistoryViewModel.cs @@ -1,7 +1,10 @@ using System; +using System.Collections.Generic; +using System.Collections.Specialized; using System.Threading.Tasks; using AutoCatCore.Model; using AutoCatCore.Services.Storage; +using ReactiveUI; namespace AutoCat.ViewModels; @@ -13,9 +16,17 @@ public class HistoryViewModel: ViewModelBase #endregion + #region Properties + + public ICollection Vehicles { get; set; } + + #endregion + public HistoryViewModel(IStorageService storageService) { _storageService = storageService; + Vehicles = storageService.GetVehicles(); + this.RaisePropertyChanged(nameof(Vehicles)); } public async Task AddVehicle(Vehicle vehicle) diff --git a/AutoCatCore/Model/VehicleEvent.cs b/AutoCatCore/Model/VehicleEvent.cs index 4ca8b21..0377289 100644 --- a/AutoCatCore/Model/VehicleEvent.cs +++ b/AutoCatCore/Model/VehicleEvent.cs @@ -2,9 +2,10 @@ namespace AutoCatCore.Model { - public class VehicleEvent + public class VehicleEvent(string id) { - public string Id { get; set; } + [MaxLength(50)] + public string Id { get; set; } = id; public double? Date { get; set; } diff --git a/AutoCatCore/Services/Storage/IStorageService.cs b/AutoCatCore/Services/Storage/IStorageService.cs index 6e82269..175df57 100644 --- a/AutoCatCore/Services/Storage/IStorageService.cs +++ b/AutoCatCore/Services/Storage/IStorageService.cs @@ -1,3 +1,4 @@ +using System.Collections.Specialized; using AutoCatCore.Model; namespace AutoCatCore.Services.Storage; @@ -11,4 +12,6 @@ public interface IStorageService public Task SetUser(User user); public Task AddVehicle(Vehicle vehicle); + + public ICollection GetVehicles(); } \ No newline at end of file diff --git a/AutoCatCore/Services/Storage/StorageService.cs b/AutoCatCore/Services/Storage/StorageService.cs index ae5109d..6bf49b8 100644 --- a/AutoCatCore/Services/Storage/StorageService.cs +++ b/AutoCatCore/Services/Storage/StorageService.cs @@ -42,8 +42,9 @@ public class StorageService: IStorageService await _dbContext.SaveChangesAsync(); } - public T GetVehicles() where T: INotifyCollectionChanged + public ICollection GetVehicles() { + _dbContext.Vehicles.Load(); return _dbContext.Vehicles.Local; } } \ No newline at end of file