Reading vehicles from database

This commit is contained in:
Selim Mustafaev 2024-05-09 01:23:52 +03:00
parent 6fad49e260
commit 5f6b71b0bd
5 changed files with 33 additions and 3 deletions

View File

@ -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 @@
</ResourceDictionary>
</UserControl.Resources>
<Grid ColumnDefinitions="300, Auto, *">
<ListBox ItemsSource="{Binding Vehicles}" Name="VehiclesList">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type models:Vehicle}">
<TextBlock Text="qwe"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
<pages:ReportPage Grid.Column="2" Vehicle="{Binding ElementName=VehiclesList, Path=SelectedItem, Mode=OneWay}"/>
</Grid>
<!--
<Grid ColumnDefinitions="300, Auto, *">
<ListBox ItemsSource="{Binding Vehicles}"
@ -28,4 +41,5 @@
<pages:ReportPage Grid.Column="2" Vehicle="{Binding ElementName=VehiclesList, Path=SelectedItem, Mode=OneWay}"/>
</Grid>
-->
</UserControl>

View File

@ -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<Vehicle> Vehicles { get; set; }
#endregion
public HistoryViewModel(IStorageService storageService)
{
_storageService = storageService;
Vehicles = storageService.GetVehicles();
this.RaisePropertyChanged(nameof(Vehicles));
}
public async Task AddVehicle(Vehicle vehicle)

View File

@ -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; }

View File

@ -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<Vehicle> GetVehicles();
}

View File

@ -42,8 +42,9 @@ public class StorageService: IStorageService
await _dbContext.SaveChangesAsync();
}
public T GetVehicles<T>() where T: INotifyCollectionChanged
public ICollection<Vehicle> GetVehicles()
{
_dbContext.Vehicles.Load();
return _dbContext.Vehicles.Local;
}
}