refactoring
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
using Data.Models.Accounts;
|
||||
using Data.Models.Currencies;
|
||||
using Data.Models.Motions;
|
||||
using Data.Models.Items;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Data.Models.Users;
|
||||
|
||||
@@ -39,10 +39,10 @@ public class AppDbContext : DbContext
|
||||
public DbSet<AccountAccountCategory> AccountAccountCategories { get; set; } = null!;
|
||||
public DbSet<AccountAccess> AccountAccesses { get; set; } = null!;
|
||||
|
||||
public DbSet<MotionGlobal> GlobalMotions { get; set; } = null!;
|
||||
public DbSet<MotionCategory> MotionCategories { get; set; } = null!;
|
||||
public DbSet<MotionAccount> Motions { get; set; } = null!;
|
||||
public DbSet<AccountMotion> AccountMotions { get; set; } = null!;
|
||||
public DbSet<ItemCategory> ItemCategories { get; set; } = null!;
|
||||
public DbSet<ItemGlobal> ItemGlobals { get; set; } = null!;
|
||||
public DbSet<Item> Items { get; set; } = null!;
|
||||
public DbSet<Motion> Motions { get; set; } = null!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ public class AppDbContext : DbContext
|
||||
modelBuilder.Entity<AccountAccess>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
modelBuilder.Entity<Motion>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<AccountCategory>()
|
||||
@@ -149,7 +149,7 @@ public class AppDbContext : DbContext
|
||||
.WithMany(x => x.AccountAccess)
|
||||
.HasForeignKey(x => x.UserId);
|
||||
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
modelBuilder.Entity<Motion>()
|
||||
.HasOne(x => x.Account)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.AccountId);
|
||||
@@ -172,45 +172,45 @@ public class AppDbContext : DbContext
|
||||
|
||||
private void MotionsCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<MotionGlobal>()
|
||||
modelBuilder.Entity<ItemGlobal>()
|
||||
.HasKey(x => x.Id);
|
||||
modelBuilder.Entity<MotionCategory>()
|
||||
modelBuilder.Entity<ItemCategory>()
|
||||
.HasKey(x => x.Id);
|
||||
modelBuilder.Entity<MotionAccount>()
|
||||
modelBuilder.Entity<Item>()
|
||||
.HasKey(x => x.Id);
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
modelBuilder.Entity<Motion>()
|
||||
.HasKey(x => x.Id);
|
||||
|
||||
modelBuilder.Entity<MotionCategory>()
|
||||
modelBuilder.Entity<ItemCategory>()
|
||||
.HasOne(x => x.User)
|
||||
.WithMany(x => x.MotionCategories)
|
||||
.WithMany(x => x.ItemCategories)
|
||||
.HasForeignKey(x => x.UserId);
|
||||
|
||||
modelBuilder.Entity<MotionAccount>()
|
||||
modelBuilder.Entity<Item>()
|
||||
.HasOne(x => x.Category)
|
||||
.WithMany(x => x.Motions)
|
||||
.WithMany(x => x.Items)
|
||||
.HasForeignKey(x => x.CategoryId);
|
||||
|
||||
modelBuilder.Entity<MotionAccount>()
|
||||
.HasOne(x => x.MotionGlobal)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.MotionGlobalId);
|
||||
modelBuilder.Entity<Item>()
|
||||
.HasOne(x => x.ItemGlobal)
|
||||
.WithMany(x => x.Items)
|
||||
.HasForeignKey(x => x.ItemGlobalId);
|
||||
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
.HasOne(x => x.Motion)
|
||||
modelBuilder.Entity<Motion>()
|
||||
.HasOne(x => x.Item)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.MotionId);
|
||||
.HasForeignKey(x => x.ItemId);
|
||||
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
modelBuilder.Entity<Motion>()
|
||||
.HasOne(x => x.Account)
|
||||
.WithMany(x => x.Motions)
|
||||
.HasForeignKey(x => x.AccountId);
|
||||
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
modelBuilder.Entity<Motion>()
|
||||
.Property(x => x.AmountMinus)
|
||||
.HasPrecision(18, 6);
|
||||
|
||||
modelBuilder.Entity<AccountMotion>()
|
||||
modelBuilder.Entity<Motion>()
|
||||
.Property(x => x.AmountPlus)
|
||||
.HasPrecision(18, 6);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class RepositoryInitializer
|
||||
new() { Id = "BTC", DefaultQuantity = 10, Symbol = "btc", Name = "Bitcoin" },
|
||||
new() { Id = "ETH", DefaultQuantity = 10, Symbol = "eth", Name = "Ethereum" },
|
||||
new() { Id = "TON", DefaultQuantity = 10, Symbol = "ton", Name = "TON" },
|
||||
new() { Id = "OTHER", DefaultQuantity = 1, Symbol = "₽", Name = "Other" },
|
||||
new() { Id = "OTHER", DefaultQuantity = 1, Symbol = "", Name = "Other" },
|
||||
};
|
||||
|
||||
var currencyGlobals = dbContext.CurrencyGlobals.ToList();
|
||||
|
||||
Reference in New Issue
Block a user