Fixing reading vehicles DB
This commit is contained in:
parent
5f6b71b0bd
commit
3a5b5f29e8
@ -20,19 +20,6 @@
|
|||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</UserControl.Resources>
|
</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, *">
|
<Grid ColumnDefinitions="300, Auto, *">
|
||||||
<ListBox ItemsSource="{Binding Vehicles}"
|
<ListBox ItemsSource="{Binding Vehicles}"
|
||||||
ItemTemplate="{StaticResource VehicleCell}"
|
ItemTemplate="{StaticResource VehicleCell}"
|
||||||
@ -40,6 +27,5 @@
|
|||||||
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
|
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
|
||||||
<pages:ReportPage Grid.Column="2" Vehicle="{Binding ElementName=VehiclesList, Path=SelectedItem, Mode=OneWay}"/>
|
<pages:ReportPage Grid.Column="2" Vehicle="{Binding ElementName=VehiclesList, Path=SelectedItem, Mode=OneWay}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
-->
|
|
||||||
|
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@ -1,46 +1,25 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AutoCat.Utils;
|
||||||
using AutoCatCore.Model;
|
using AutoCatCore.Model;
|
||||||
using AutoCatCore.Services.Storage;
|
using AutoCatCore.Services.Storage;
|
||||||
using ReactiveUI;
|
|
||||||
|
|
||||||
namespace AutoCat.ViewModels;
|
namespace AutoCat.ViewModels;
|
||||||
|
|
||||||
public class HistoryViewModel: ViewModelBase
|
public class HistoryViewModel(IStorageService storageService) : ViewModelBase
|
||||||
{
|
{
|
||||||
#region Dependencies
|
public ObservableCollection<Vehicle> Vehicles { get; set; } = storageService.GetVehicles();
|
||||||
|
|
||||||
private readonly IStorageService _storageService;
|
|
||||||
|
|
||||||
#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)
|
public async Task AddVehicle(Vehicle vehicle)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _storageService.AddVehicle(vehicle);
|
await storageService.AddVehicle(vehicle);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Exception: {ex.Message}");
|
Alerts.ShowError(ex);
|
||||||
Console.WriteLine($"Inner exception: {ex.InnerException?.Message}");
|
}
|
||||||
Console.WriteLine("");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -14,6 +14,7 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Realm" Version="12.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
3
AutoCatCore/FodyWeavers.xml
Normal file
3
AutoCatCore/FodyWeavers.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||||
|
<Realm />
|
||||||
|
</Weavers>
|
||||||
72
AutoCatCore/FodyWeavers.xsd
Normal file
72
AutoCatCore/FodyWeavers.xsd
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
|
||||||
|
<xs:element name="Weavers">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:all>
|
||||||
|
<xs:element name="Realm" minOccurs="0" maxOccurs="1">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name="DisableAnalytics" type="xs:boolean">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>THIS IS DEPRECATED - USE `AnalyticsCollection` INSTEAD. Disables anonymized
|
||||||
|
usage information from being sent on build. Read more about what data is being collected and
|
||||||
|
why here: https://github.com/realm/realm-dotnet/blob/main/Realm/Realm.Weaver/Analytics.cs</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="AnalyticsCollection">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>Controls what anonymized usage information is being sent on build. Read more
|
||||||
|
about what data is being collected and why here:
|
||||||
|
https://github.com/realm/realm-dotnet/blob/main/Realm/Realm.Weaver/Analytics/Analytics.cs</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="Full">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>Analytics collection will run normally. This is the default behavior
|
||||||
|
and we hope you don't change it as the anonymized data collected is critical for
|
||||||
|
making the right decisions about the future of the Realm SDK.</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:enumeration>
|
||||||
|
<xs:enumeration value="DryRun">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>Analytics collection will run but will not send it to the server. This
|
||||||
|
is useful in combination with `AnalyticsLogPath` if you want to review the data being
|
||||||
|
sent.</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:enumeration>
|
||||||
|
<xs:enumeration value="Disabled">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>Analytics collection is disabled. No data will be sent on build.</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:enumeration>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="AnalyticsLogPath" type="xs:string">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>Controls where the payload for the anonymized metrics collection will be
|
||||||
|
stored. This can be useful if you want to review the data being collected by Realm. </xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:attribute>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:all>
|
||||||
|
<xs:attribute name="VerifyAssembly" type="xs:boolean">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:attribute>
|
||||||
|
<xs:attribute name="GenerateXsd" type="xs:boolean">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:attribute>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:schema>
|
||||||
@ -1,5 +1,7 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using AutoCatCore.Model;
|
using AutoCatCore.Model;
|
||||||
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
|
||||||
namespace AutoCatCore.Services.Storage;
|
namespace AutoCatCore.Services.Storage;
|
||||||
|
|
||||||
@ -13,5 +15,5 @@ public interface IStorageService
|
|||||||
|
|
||||||
public Task AddVehicle(Vehicle vehicle);
|
public Task AddVehicle(Vehicle vehicle);
|
||||||
|
|
||||||
public ICollection<Vehicle> GetVehicles();
|
public ObservableCollection<Vehicle> GetVehicles();
|
||||||
}
|
}
|
||||||
@ -42,9 +42,9 @@ public class StorageService: IStorageService
|
|||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<Vehicle> GetVehicles()
|
public ObservableCollection<Vehicle> GetVehicles()
|
||||||
{
|
{
|
||||||
_dbContext.Vehicles.Load();
|
_dbContext.Vehicles.Load();
|
||||||
return _dbContext.Vehicles.Local;
|
return _dbContext.Vehicles.Local.ToObservableCollection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user