Switch DB from Entity Framework Core to Realm.NET

This commit is contained in:
Selim Mustafaev 2024-05-09 17:09:58 +03:00
parent 3a5b5f29e8
commit 0d1ef6e853
30 changed files with 69 additions and 1571 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using Avalonia.Data.Converters; using Avalonia.Data.Converters;
@ -20,6 +21,7 @@ public class DateConverter: IValueConverter
return dateTime.ToString("g"); return dateTime.ToString("g");
} }
[SuppressMessage("ReSharper", "ReturnTypeCanBeNotNullable")]
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -10,9 +10,9 @@ public class HistoryListViewModelMock: ViewModelBase
public HistoryListViewModelMock() public HistoryListViewModelMock()
{ {
var vehicle1 = new Vehicle("А007АА761"); var vehicle1 = new Vehicle { Number = "А007АА761" };
var vehicle2 = new Vehicle("А007АА761"); var vehicle2 = new Vehicle { Number = "А007АА761" };
var vehicle3 = new Vehicle("А007АА761"); var vehicle3 = new Vehicle { Number = "А007АА761" };
Vehicles = new ObservableCollection<Vehicle> { vehicle1, vehicle2, vehicle3 }; Vehicles = new ObservableCollection<Vehicle> { vehicle1, vehicle2, vehicle3 };
} }

View File

@ -5,7 +5,6 @@
xmlns:pages="clr-namespace:AutoCat.Pages" xmlns:pages="clr-namespace:AutoCat.Pages"
xmlns:utils="using:AutoCat.Utils" xmlns:utils="using:AutoCat.Utils"
xmlns:vm="using:AutoCat.ViewModels" xmlns:vm="using:AutoCat.ViewModels"
xmlns:models="using:AutoCatCore.Model"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AutoCat.Pages.HistoryPage" x:Class="AutoCat.Pages.HistoryPage"
x:DataType="vm:HistoryViewModel" x:DataType="vm:HistoryViewModel"

View File

@ -1,6 +1,4 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace AutoCat.Pages; namespace AutoCat.Pages;

View File

@ -24,7 +24,7 @@ public class CheckNumberViewModel : ViewModelBase
#region Commands #region Commands
public ReactiveCommand<string, Unit> CheckCommand { get; } public ReactiveCommand<string, Unit> CheckCommand { get; set; }
#endregion #endregion

View File

@ -1,5 +1,5 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoCat.Utils; using AutoCat.Utils;
using AutoCatCore.Model; using AutoCatCore.Model;
@ -9,7 +9,7 @@ namespace AutoCat.ViewModels;
public class HistoryViewModel(IStorageService storageService) : ViewModelBase public class HistoryViewModel(IStorageService storageService) : ViewModelBase
{ {
public ObservableCollection<Vehicle> Vehicles { get; set; } = storageService.GetVehicles(); public IEnumerable<Vehicle> Vehicles { get; } = storageService.AllVehicles;
public async Task AddVehicle(Vehicle vehicle) public async Task AddVehicle(Vehicle vehicle)
{ {

View File

@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using AutoCatCore.Model; using AutoCatCore.Model;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
@ -45,6 +46,7 @@ public partial class PlateView : UserControl
RegionBox.Text = number.Region(); RegionBox.Text = number.Region();
} }
[SuppressMessage("ReSharper", "UnusedParameter.Local")]
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{ {
if(Bounds.Height <= 0) if(Bounds.Height <= 0)

View File

@ -10,7 +10,7 @@
x:Class="AutoCat.Windows.AuthWindow" x:Class="AutoCat.Windows.AuthWindow"
x:DataType="vm:AuthWindowViewModel" x:DataType="vm:AuthWindowViewModel"
Title="AuthWindow" Title="AuthWindow"
Width="800" Height="600" Width="900" Height="600"
DataContext="{utils:ViewModelProvider vm:AuthWindowViewModel}"> DataContext="{utils:ViewModelProvider vm:AuthWindowViewModel}">
<Design.DataContext> <Design.DataContext>

View File

@ -6,7 +6,7 @@
xmlns:utils="using:AutoCat.Utils" xmlns:utils="using:AutoCat.Utils"
xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:ui="using:FluentAvalonia.UI.Controls"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Width="800" Width="900"
Height="600" Height="600"
x:Class="AutoCat.Windows.MainWindow" x:Class="AutoCat.Windows.MainWindow"
x:DataType="vm:MainWindowViewModel" x:DataType="vm:MainWindowViewModel"

View File

@ -1,9 +1,6 @@
using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using AutoCat.Pages; using AutoCat.Pages;
using AutoCat.ViewModels; using AutoCat.ViewModels;
using AutoCatCore.Model;
using Avalonia.Controls; using Avalonia.Controls;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;

View File

@ -8,12 +8,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageReference Include="Realm" Version="12.1.0" /> <PackageReference Include="Realm" Version="12.1.0" />
</ItemGroup> </ItemGroup>

View File

@ -1,510 +0,0 @@
// <auto-generated />
using System;
using AutoCatCore.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace AutoCatCore.Migrations
{
[DbContext(typeof(AutoCatDbContext))]
[Migration("20240508141817_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");
modelBuilder.Entity("AutoCatCore.Model.Osago", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<double?>("Date")
.HasColumnType("REAL");
b.Property<string>("Insurant")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Number")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Owner")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("PlateNumber")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Restrictions")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Status")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("UsageRegion")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.Property<string>("Vin")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("Osago");
});
modelBuilder.Entity("AutoCatCore.Model.User", b =>
{
b.Property<string>("Email")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("FirebaseIdToken")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<string>("FirebaseRefreshToken")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<string>("Token")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.HasKey("Email");
b.ToTable("Users");
});
modelBuilder.Entity("AutoCatCore.Model.Vehicle", b =>
{
b.Property<string>("Number")
.HasMaxLength(10)
.HasColumnType("TEXT");
b.Property<string>("AddedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("AddedDate")
.HasColumnType("REAL");
b.Property<int?>("BrandId")
.HasColumnType("INTEGER");
b.Property<string>("Category")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Color")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("CurrentNumber")
.HasMaxLength(10)
.HasColumnType("TEXT");
b.Property<int?>("EngineId")
.HasColumnType("INTEGER");
b.Property<bool?>("IsJapanese")
.HasColumnType("INTEGER");
b.Property<bool?>("IsRightWheel")
.HasColumnType("INTEGER");
b.Property<int?>("ModelId")
.HasColumnType("INTEGER");
b.Property<string>("Pts")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Sts")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<double?>("UpdatedDate")
.HasColumnType("REAL");
b.Property<string>("Vin1")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Vin2")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int?>("Year")
.HasColumnType("INTEGER");
b.HasKey("Number");
b.HasIndex("BrandId");
b.HasIndex("EngineId");
b.HasIndex("ModelId");
b.ToTable("Vehicles");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleAd", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AdDescription")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("City")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("Date")
.HasMaxLength(50)
.HasColumnType("REAL");
b.Property<string>("Mileage")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Photos")
.HasColumnType("TEXT");
b.Property<string>("Price")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Region")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Url")
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("VehicleAd");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Logo")
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<int?>("NameId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("NameId");
b.ToTable("VehicleBrand");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleEngine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("FuelType")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Number")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("PowerHp")
.HasColumnType("REAL");
b.Property<double?>("PowerKw")
.HasColumnType("REAL");
b.Property<int?>("Volume")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("VehicleEngine");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleEvent", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Address")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("Date")
.HasColumnType("REAL");
b.Property<double?>("Latitude")
.HasColumnType("REAL");
b.Property<double?>("Longitude")
.HasColumnType("REAL");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("VehicleEvent");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleModel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("NameId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("NameId");
b.ToTable("VehicleModel");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleName", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Normalized")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Original")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("VehicleName");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleOwnershipPeriod", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Building")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Code")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<long?>("From")
.HasColumnType("INTEGER");
b.Property<string>("Inn")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("LastOperation")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Locality")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("OwnerType")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Region")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<string>("RegistrationRegion")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<string>("Street")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<long?>("To")
.HasColumnType("INTEGER");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("VehicleOwnershipPeriod");
});
modelBuilder.Entity("AutoCatCore.Model.VehiclePhoto", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Brand")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("Date")
.HasColumnType("REAL");
b.Property<string>("Model")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Url")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("VehiclePhoto");
});
modelBuilder.Entity("AutoCatCore.Model.Osago", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("OsagoContracts")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.Vehicle", b =>
{
b.HasOne("AutoCatCore.Model.VehicleBrand", "Brand")
.WithMany()
.HasForeignKey("BrandId");
b.HasOne("AutoCatCore.Model.VehicleEngine", "Engine")
.WithMany()
.HasForeignKey("EngineId");
b.HasOne("AutoCatCore.Model.VehicleModel", "Model")
.WithMany()
.HasForeignKey("ModelId");
b.Navigation("Brand");
b.Navigation("Engine");
b.Navigation("Model");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleAd", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("Ads")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleBrand", b =>
{
b.HasOne("AutoCatCore.Model.VehicleName", "Name")
.WithMany()
.HasForeignKey("NameId");
b.Navigation("Name");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleEvent", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("Events")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleModel", b =>
{
b.HasOne("AutoCatCore.Model.VehicleName", "Name")
.WithMany()
.HasForeignKey("NameId");
b.Navigation("Name");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleOwnershipPeriod", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("OwnershipPeriods")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.VehiclePhoto", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("Photos")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.Vehicle", b =>
{
b.Navigation("Ads");
b.Navigation("Events");
b.Navigation("OsagoContracts");
b.Navigation("OwnershipPeriods");
b.Navigation("Photos");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,351 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AutoCatCore.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Email = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
Token = table.Column<string>(type: "TEXT", maxLength: 300, nullable: true),
FirebaseIdToken = table.Column<string>(type: "TEXT", maxLength: 300, nullable: true),
FirebaseRefreshToken = table.Column<string>(type: "TEXT", maxLength: 300, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Email);
});
migrationBuilder.CreateTable(
name: "VehicleEngine",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Number = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Volume = table.Column<int>(type: "INTEGER", nullable: true),
PowerKw = table.Column<double>(type: "REAL", nullable: true),
PowerHp = table.Column<double>(type: "REAL", nullable: true),
FuelType = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VehicleEngine", x => x.Id);
});
migrationBuilder.CreateTable(
name: "VehicleName",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Original = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Normalized = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VehicleName", x => x.Id);
});
migrationBuilder.CreateTable(
name: "VehicleBrand",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
NameId = table.Column<int>(type: "INTEGER", nullable: true),
Logo = table.Column<string>(type: "TEXT", maxLength: 200, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VehicleBrand", x => x.Id);
table.ForeignKey(
name: "FK_VehicleBrand_VehicleName_NameId",
column: x => x.NameId,
principalTable: "VehicleName",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "VehicleModel",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
NameId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VehicleModel", x => x.Id);
table.ForeignKey(
name: "FK_VehicleModel_VehicleName_NameId",
column: x => x.NameId,
principalTable: "VehicleName",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Vehicles",
columns: table => new
{
Number = table.Column<string>(type: "TEXT", maxLength: 10, nullable: false),
CurrentNumber = table.Column<string>(type: "TEXT", maxLength: 10, nullable: true),
Vin1 = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
Vin2 = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
Sts = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
Pts = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
BrandId = table.Column<int>(type: "INTEGER", nullable: true),
ModelId = table.Column<int>(type: "INTEGER", nullable: true),
Color = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Year = table.Column<int>(type: "INTEGER", nullable: true),
Category = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
IsRightWheel = table.Column<bool>(type: "INTEGER", nullable: true),
IsJapanese = table.Column<bool>(type: "INTEGER", nullable: true),
AddedDate = table.Column<double>(type: "REAL", nullable: true),
UpdatedDate = table.Column<double>(type: "REAL", nullable: true),
AddedBy = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
EngineId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Vehicles", x => x.Number);
table.ForeignKey(
name: "FK_Vehicles_VehicleBrand_BrandId",
column: x => x.BrandId,
principalTable: "VehicleBrand",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Vehicles_VehicleEngine_EngineId",
column: x => x.EngineId,
principalTable: "VehicleEngine",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Vehicles_VehicleModel_ModelId",
column: x => x.ModelId,
principalTable: "VehicleModel",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Osago",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Number = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
Date = table.Column<double>(type: "REAL", nullable: true),
Vin = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
PlateNumber = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Status = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Restrictions = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
Insurant = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Owner = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
UsageRegion = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
VehicleNumber = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Osago", x => x.Id);
table.ForeignKey(
name: "FK_Osago_Vehicles_VehicleNumber",
column: x => x.VehicleNumber,
principalTable: "Vehicles",
principalColumn: "Number");
});
migrationBuilder.CreateTable(
name: "VehicleAd",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Url = table.Column<string>(type: "TEXT", maxLength: 200, nullable: true),
Price = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
Date = table.Column<double>(type: "REAL", maxLength: 50, nullable: true),
Mileage = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
Region = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
City = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
AdDescription = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
Photos = table.Column<string>(type: "TEXT", nullable: true),
VehicleNumber = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VehicleAd", x => x.Id);
table.ForeignKey(
name: "FK_VehicleAd_Vehicles_VehicleNumber",
column: x => x.VehicleNumber,
principalTable: "Vehicles",
principalColumn: "Number");
});
migrationBuilder.CreateTable(
name: "VehicleEvent",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Date = table.Column<double>(type: "REAL", nullable: true),
Latitude = table.Column<double>(type: "REAL", nullable: true),
Longitude = table.Column<double>(type: "REAL", nullable: true),
Address = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
VehicleNumber = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VehicleEvent", x => x.Id);
table.ForeignKey(
name: "FK_VehicleEvent_Vehicles_VehicleNumber",
column: x => x.VehicleNumber,
principalTable: "Vehicles",
principalColumn: "Number");
});
migrationBuilder.CreateTable(
name: "VehicleOwnershipPeriod",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
LastOperation = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
OwnerType = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
From = table.Column<long>(type: "INTEGER", nullable: true),
To = table.Column<long>(type: "INTEGER", nullable: true),
Region = table.Column<string>(type: "TEXT", maxLength: 300, nullable: true),
RegistrationRegion = table.Column<string>(type: "TEXT", maxLength: 300, nullable: true),
Locality = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Code = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Street = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Building = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Inn = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
VehicleNumber = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VehicleOwnershipPeriod", x => x.Id);
table.ForeignKey(
name: "FK_VehicleOwnershipPeriod_Vehicles_VehicleNumber",
column: x => x.VehicleNumber,
principalTable: "Vehicles",
principalColumn: "Number");
});
migrationBuilder.CreateTable(
name: "VehiclePhoto",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Brand = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Model = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Date = table.Column<double>(type: "REAL", nullable: true),
Url = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
VehicleNumber = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_VehiclePhoto", x => x.Id);
table.ForeignKey(
name: "FK_VehiclePhoto_Vehicles_VehicleNumber",
column: x => x.VehicleNumber,
principalTable: "Vehicles",
principalColumn: "Number");
});
migrationBuilder.CreateIndex(
name: "IX_Osago_VehicleNumber",
table: "Osago",
column: "VehicleNumber");
migrationBuilder.CreateIndex(
name: "IX_VehicleAd_VehicleNumber",
table: "VehicleAd",
column: "VehicleNumber");
migrationBuilder.CreateIndex(
name: "IX_VehicleBrand_NameId",
table: "VehicleBrand",
column: "NameId");
migrationBuilder.CreateIndex(
name: "IX_VehicleEvent_VehicleNumber",
table: "VehicleEvent",
column: "VehicleNumber");
migrationBuilder.CreateIndex(
name: "IX_VehicleModel_NameId",
table: "VehicleModel",
column: "NameId");
migrationBuilder.CreateIndex(
name: "IX_VehicleOwnershipPeriod_VehicleNumber",
table: "VehicleOwnershipPeriod",
column: "VehicleNumber");
migrationBuilder.CreateIndex(
name: "IX_VehiclePhoto_VehicleNumber",
table: "VehiclePhoto",
column: "VehicleNumber");
migrationBuilder.CreateIndex(
name: "IX_Vehicles_BrandId",
table: "Vehicles",
column: "BrandId");
migrationBuilder.CreateIndex(
name: "IX_Vehicles_EngineId",
table: "Vehicles",
column: "EngineId");
migrationBuilder.CreateIndex(
name: "IX_Vehicles_ModelId",
table: "Vehicles",
column: "ModelId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Osago");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "VehicleAd");
migrationBuilder.DropTable(
name: "VehicleEvent");
migrationBuilder.DropTable(
name: "VehicleOwnershipPeriod");
migrationBuilder.DropTable(
name: "VehiclePhoto");
migrationBuilder.DropTable(
name: "Vehicles");
migrationBuilder.DropTable(
name: "VehicleBrand");
migrationBuilder.DropTable(
name: "VehicleEngine");
migrationBuilder.DropTable(
name: "VehicleModel");
migrationBuilder.DropTable(
name: "VehicleName");
}
}
}

View File

@ -1,507 +0,0 @@
// <auto-generated />
using System;
using AutoCatCore.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace AutoCatCore.Migrations
{
[DbContext(typeof(AutoCatDbContext))]
partial class AutoCatDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");
modelBuilder.Entity("AutoCatCore.Model.Osago", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<double?>("Date")
.HasColumnType("REAL");
b.Property<string>("Insurant")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Number")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Owner")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("PlateNumber")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Restrictions")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Status")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("UsageRegion")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.Property<string>("Vin")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("Osago");
});
modelBuilder.Entity("AutoCatCore.Model.User", b =>
{
b.Property<string>("Email")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("FirebaseIdToken")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<string>("FirebaseRefreshToken")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<string>("Token")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.HasKey("Email");
b.ToTable("Users");
});
modelBuilder.Entity("AutoCatCore.Model.Vehicle", b =>
{
b.Property<string>("Number")
.HasMaxLength(10)
.HasColumnType("TEXT");
b.Property<string>("AddedBy")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("AddedDate")
.HasColumnType("REAL");
b.Property<int?>("BrandId")
.HasColumnType("INTEGER");
b.Property<string>("Category")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Color")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("CurrentNumber")
.HasMaxLength(10)
.HasColumnType("TEXT");
b.Property<int?>("EngineId")
.HasColumnType("INTEGER");
b.Property<bool?>("IsJapanese")
.HasColumnType("INTEGER");
b.Property<bool?>("IsRightWheel")
.HasColumnType("INTEGER");
b.Property<int?>("ModelId")
.HasColumnType("INTEGER");
b.Property<string>("Pts")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Sts")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<double?>("UpdatedDate")
.HasColumnType("REAL");
b.Property<string>("Vin1")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Vin2")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int?>("Year")
.HasColumnType("INTEGER");
b.HasKey("Number");
b.HasIndex("BrandId");
b.HasIndex("EngineId");
b.HasIndex("ModelId");
b.ToTable("Vehicles");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleAd", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AdDescription")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("City")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("Date")
.HasMaxLength(50)
.HasColumnType("REAL");
b.Property<string>("Mileage")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Photos")
.HasColumnType("TEXT");
b.Property<string>("Price")
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Region")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Url")
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("VehicleAd");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Logo")
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<int?>("NameId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("NameId");
b.ToTable("VehicleBrand");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleEngine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("FuelType")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Number")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("PowerHp")
.HasColumnType("REAL");
b.Property<double?>("PowerKw")
.HasColumnType("REAL");
b.Property<int?>("Volume")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("VehicleEngine");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleEvent", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Address")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("Date")
.HasColumnType("REAL");
b.Property<double?>("Latitude")
.HasColumnType("REAL");
b.Property<double?>("Longitude")
.HasColumnType("REAL");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("VehicleEvent");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleModel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int?>("NameId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("NameId");
b.ToTable("VehicleModel");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleName", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Normalized")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Original")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("VehicleName");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleOwnershipPeriod", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Building")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Code")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<long?>("From")
.HasColumnType("INTEGER");
b.Property<string>("Inn")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("LastOperation")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Locality")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("OwnerType")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Region")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<string>("RegistrationRegion")
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<string>("Street")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<long?>("To")
.HasColumnType("INTEGER");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("VehicleOwnershipPeriod");
});
modelBuilder.Entity("AutoCatCore.Model.VehiclePhoto", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Brand")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double?>("Date")
.HasColumnType("REAL");
b.Property<string>("Model")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("Url")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("VehicleNumber")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("VehicleNumber");
b.ToTable("VehiclePhoto");
});
modelBuilder.Entity("AutoCatCore.Model.Osago", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("OsagoContracts")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.Vehicle", b =>
{
b.HasOne("AutoCatCore.Model.VehicleBrand", "Brand")
.WithMany()
.HasForeignKey("BrandId");
b.HasOne("AutoCatCore.Model.VehicleEngine", "Engine")
.WithMany()
.HasForeignKey("EngineId");
b.HasOne("AutoCatCore.Model.VehicleModel", "Model")
.WithMany()
.HasForeignKey("ModelId");
b.Navigation("Brand");
b.Navigation("Engine");
b.Navigation("Model");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleAd", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("Ads")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleBrand", b =>
{
b.HasOne("AutoCatCore.Model.VehicleName", "Name")
.WithMany()
.HasForeignKey("NameId");
b.Navigation("Name");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleEvent", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("Events")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleModel", b =>
{
b.HasOne("AutoCatCore.Model.VehicleName", "Name")
.WithMany()
.HasForeignKey("NameId");
b.Navigation("Name");
});
modelBuilder.Entity("AutoCatCore.Model.VehicleOwnershipPeriod", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("OwnershipPeriods")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.VehiclePhoto", b =>
{
b.HasOne("AutoCatCore.Model.Vehicle", null)
.WithMany("Photos")
.HasForeignKey("VehicleNumber");
});
modelBuilder.Entity("AutoCatCore.Model.Vehicle", b =>
{
b.Navigation("Ads");
b.Navigation("Events");
b.Navigation("OsagoContracts");
b.Navigation("OwnershipPeriods");
b.Navigation("Photos");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,16 +0,0 @@
using Microsoft.EntityFrameworkCore;
namespace AutoCatCore.Model
{
class AutoCatDbContext: DbContext
{
public DbSet<User> Users { get; private set; }
public DbSet<Vehicle> Vehicles { get; private set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("filename=autocat.db");
}
}
}

View File

@ -1,28 +1,18 @@
using System.ComponentModel.DataAnnotations; using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class Osago public class Osago: EmbeddedObject
{ {
public int Id { get; set; }
[MaxLength(50)]
public string? Number { get; set; } public string? Number { get; set; }
public double? Date { get; set; } public double? Date { get; set; }
[MaxLength(50)]
public string? Vin { get; set; } public string? Vin { get; set; }
[MaxLength(50)]
public string? PlateNumber { get; set; } public string? PlateNumber { get; set; }
[MaxLength(100)]
public string? Name { get; set; } public string? Name { get; set; }
[MaxLength(100)]
public string? Status { get; set; } public string? Status { get; set; }
[MaxLength(500)]
public string? Restrictions { get; set; } public string? Restrictions { get; set; }
[MaxLength(100)]
public string? Insurant { get; set; } public string? Insurant { get; set; }
[MaxLength(100)]
public string? Owner { get; set; } public string? Owner { get; set; }
[MaxLength(100)]
public string? UsageRegion { get; set; } public string? UsageRegion { get; set; }
} }
} }

View File

@ -1,23 +1,18 @@
using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization;
using System.Text.Json.Serialization; using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class User(string email, string token) public class User: RealmObject
{ {
[Key] public string Email { get; set; } = "";
[MaxLength(50)]
public string Email { get; init; } = email;
[MaxLength(300)] public string? Token { get; set; } = null;
public string? Token { get; init; } = token;
[JsonIgnore] [JsonIgnore]
[MaxLength(300)]
public string? FirebaseIdToken { get; init; } public string? FirebaseIdToken { get; init; }
[JsonIgnore] [JsonIgnore]
[MaxLength(300)]
public string? FirebaseRefreshToken { get; init; } public string? FirebaseRefreshToken { get; init; }
} }
} }

View File

@ -1,55 +1,33 @@
using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis;
using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class Vehicle(string number) [SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
public class Vehicle: RealmObject
{ {
[Key] [MaxLength(10)] [PrimaryKey]
public string Number { get; set; } = number; public string Number { get; set; } = "";
[MaxLength(10)]
public string? CurrentNumber { get; set; } public string? CurrentNumber { get; set; }
[MaxLength(50)]
public string? Vin1 { get; set; } public string? Vin1 { get; set; }
[MaxLength(50)]
public string? Vin2 { get; set; } public string? Vin2 { get; set; }
[MaxLength(50)]
public string? Sts { get; set; } public string? Sts { get; set; }
[MaxLength(50)]
public string? Pts { get; set; } public string? Pts { get; set; }
public VehicleBrand? Brand { get; set; } public VehicleBrand? Brand { get; set; }
public VehicleModel? Model { get; set; } public VehicleModel? Model { get; set; }
[MaxLength(100)]
public string? Color { get; set; } public string? Color { get; set; }
public int? Year { get; set; } public int? Year { get; set; }
[MaxLength(100)]
public string? Category { get; set; } public string? Category { get; set; }
public bool? IsRightWheel { get; set; } public bool? IsRightWheel { get; set; }
public bool? IsJapanese { get; set; } public bool? IsJapanese { get; set; }
public double? AddedDate { get; set; } public double? AddedDate { get; set; }
public double? UpdatedDate { get; set; } public double? UpdatedDate { get; set; }
[MaxLength(100)]
public string? AddedBy { get; set; } public string? AddedBy { get; set; }
public VehicleEngine? Engine { get; set; } public VehicleEngine? Engine { get; set; }
public List<VehiclePhoto>? Photos { get; set; } public IList<VehiclePhoto>? Photos { get; }
public List<VehicleEvent>? Events { get; set; } public IList<VehicleEvent>? Events { get; }
public List<Osago>? OsagoContracts { get; set; } public IList<Osago>? OsagoContracts { get; }
public List<VehicleOwnershipPeriod>? OwnershipPeriods { get; set; } public IList<VehicleOwnershipPeriod>? OwnershipPeriods { get; }
public List<VehicleAd>? Ads { get; set; } public IList<VehicleAd>? Ads { get; }
} }
} }

View File

@ -1,24 +1,18 @@
using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis;
using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class VehicleAd [SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
public class VehicleAd: EmbeddedObject
{ {
public int Id { get; set; }
[MaxLength(200)]
public string? Url { get; set; } public string? Url { get; set; }
[MaxLength(50)]
public string? Price { get; set; } public string? Price { get; set; }
[MaxLength(50)]
public double? Date { get; set; } public double? Date { get; set; }
[MaxLength(50)]
public string? Mileage { get; set; } public string? Mileage { get; set; }
[MaxLength(100)]
public string? Region { get; set; } public string? Region { get; set; }
[MaxLength(100)]
public string? City { get; set; } public string? City { get; set; }
[MaxLength(500)]
public string? AdDescription { get; set; } public string? AdDescription { get; set; }
public List<string>? Photos { get; set; } public IList<string>? Photos { get; }
} }
} }

View File

@ -1,14 +1,10 @@
using System.ComponentModel.DataAnnotations; using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class VehicleBrand public class VehicleBrand: EmbeddedObject
{ {
public int Id { get; set; }
public VehicleName? Name { get; set; } public VehicleName? Name { get; set; }
[MaxLength(200)]
public string? Logo { get; set; } public string? Logo { get; set; }
} }
} }

View File

@ -1,21 +1,13 @@
using System.ComponentModel.DataAnnotations; using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class VehicleEngine public class VehicleEngine: EmbeddedObject
{ {
public int Id { get; set; }
[MaxLength(100)]
public string? Number { get; set; } public string? Number { get; set; }
public int? Volume { get; set; } public int? Volume { get; set; }
public double? PowerKw { get; set; } public double? PowerKw { get; set; }
public double? PowerHp { get; set; } public double? PowerHp { get; set; }
[MaxLength(100)]
public string? FuelType { get; set; } public string? FuelType { get; set; }
} }
} }

View File

@ -1,19 +1,13 @@
using System.ComponentModel.DataAnnotations; using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class VehicleEvent(string id) public class VehicleEvent: EmbeddedObject
{ {
[MaxLength(50)] public string Id { get; set; } = "";
public string Id { get; set; } = id;
public double? Date { get; set; } public double? Date { get; set; }
public double? Latitude { get; set; } public double? Latitude { get; set; }
public double? Longitude { get; set; } public double? Longitude { get; set; }
[MaxLength(100)]
public string? Address { get; set; } public string? Address { get; set; }
} }
} }

View File

@ -1,8 +1,9 @@
namespace AutoCatCore.Model using Realms;
namespace AutoCatCore.Model
{ {
public class VehicleModel public class VehicleModel: EmbeddedObject
{ {
public int Id { get; set; }
public VehicleName? Name { get; set; } public VehicleName? Name { get; set; }
} }
} }

View File

@ -1,16 +1,10 @@
using System.ComponentModel.DataAnnotations; using Realms;
using System.ComponentModel.DataAnnotations.Schema;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class VehicleName public class VehicleName: EmbeddedObject
{ {
public int Id { get; set; }
[MaxLength(100)]
public string? Original { get; set; } public string? Original { get; set; }
[MaxLength(100)]
public string? Normalized { get; set; } public string? Normalized { get; set; }
} }
} }

View File

@ -1,40 +1,19 @@
using System.ComponentModel.DataAnnotations; using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class VehicleOwnershipPeriod public class VehicleOwnershipPeriod: EmbeddedObject
{ {
public int Id { get; set; }
[MaxLength(500)]
public string? LastOperation { get; set; } public string? LastOperation { get; set; }
[MaxLength(100)]
public string? OwnerType { get; set; } public string? OwnerType { get; set; }
public long? From { get; set; } public long? From { get; set; }
public long? To { get; set; } public long? To { get; set; }
[MaxLength(300)]
public string? Region { get; set; } public string? Region { get; set; }
[MaxLength(300)]
public string? RegistrationRegion { get; set; } public string? RegistrationRegion { get; set; }
[MaxLength(100)]
public string? Locality { get; set; } public string? Locality { get; set; }
[MaxLength(100)]
public string? Code { get; set; } public string? Code { get; set; }
[MaxLength(100)]
public string? Street { get; set; } public string? Street { get; set; }
[MaxLength(100)]
public string? Building { get; set; } public string? Building { get; set; }
[MaxLength(100)]
public string? Inn { get; set; } public string? Inn { get; set; }
} }
} }

View File

@ -1,20 +1,12 @@
using System.ComponentModel.DataAnnotations; using Realms;
namespace AutoCatCore.Model namespace AutoCatCore.Model
{ {
public class VehiclePhoto public class VehiclePhoto: EmbeddedObject
{ {
public int Id { get; set; }
[MaxLength(100)]
public string? Brand { get; set; } public string? Brand { get; set; }
[MaxLength(100)]
public string? Model { get; set; } public string? Model { get; set; }
public double? Date { get; set; } public double? Date { get; set; }
[MaxLength(500)]
public string? Url { get; set; } public string? Url { get; set; }
} }
} }

View File

@ -1,5 +1,4 @@
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Text;
using System.Text.Json; using System.Text.Json;
using AutoCatCore.Model; using AutoCatCore.Model;
using AutoCatCore.Model.Requests; using AutoCatCore.Model.Requests;

View File

@ -1,7 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using AutoCatCore.Model; using AutoCatCore.Model;
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace AutoCatCore.Services.Storage; namespace AutoCatCore.Services.Storage;
@ -15,5 +12,5 @@ public interface IStorageService
public Task AddVehicle(Vehicle vehicle); public Task AddVehicle(Vehicle vehicle);
public ObservableCollection<Vehicle> GetVehicles(); public IEnumerable<Vehicle> AllVehicles { get; }
} }

View File

@ -1,50 +1,39 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using AutoCatCore.Model; using AutoCatCore.Model;
using Microsoft.EntityFrameworkCore; using Realms;
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace AutoCatCore.Services.Storage; namespace AutoCatCore.Services.Storage;
public class StorageService: IStorageService public class StorageService: IStorageService
{ {
private readonly AutoCatDbContext _dbContext; private readonly Realm _realm = Realm.GetInstance();
public bool IsLoggedIn public bool IsLoggedIn
{ {
get get
{ {
if (_dbContext.Users.Any()) var user = _realm.All<User>().FirstOrDefault();
return _dbContext.Users.First().Token != null; return user?.Token != null;
else
return false;
} }
} }
public string? AuthToken => _dbContext.Users.Any() ? _dbContext.Users.First().Token : null; public string? AuthToken => _realm.All<User>().FirstOrDefault()?.Token;
public StorageService()
{
_dbContext = new AutoCatDbContext();
_dbContext.Database.EnsureCreated();
}
public async Task SetUser(User user) public async Task SetUser(User user)
{ {
await _dbContext.Users.ExecuteDeleteAsync(); await _realm.WriteAsync(() =>
await _dbContext.Users.AddAsync(user); {
await _dbContext.SaveChangesAsync(); _realm.RemoveAll<User>();
_realm.Add(user);
});
} }
public async Task AddVehicle(Vehicle vehicle) public async Task AddVehicle(Vehicle vehicle)
{ {
await _dbContext.Vehicles.AddAsync(vehicle); await _realm.WriteAsync(() =>
await _dbContext.SaveChangesAsync(); {
_realm.Add(vehicle);
});
} }
public ObservableCollection<Vehicle> GetVehicles() public IEnumerable<Vehicle> AllVehicles => _realm.All<Vehicle>();
{
_dbContext.Vehicles.Load();
return _dbContext.Vehicles.Local.ToObservableCollection();
}
} }

Binary file not shown.