В автомате не пашет, выкручиваемся

This commit is contained in:
Artyom_Yashin 2024-05-04 23:10:34 +04:00
parent a35b849ea5
commit 3ae9e96335
8 changed files with 1156 additions and 16 deletions

View File

@ -17,7 +17,17 @@ namespace BankDatabaseImplement
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Transfer>()
modelBuilder.Entity<Operation>()
.HasOne(o => o.Transfer)
.WithOne(t => t.Operation)
.HasForeignKey<Transfer>(t => t.OperationId)
.IsRequired(false);
modelBuilder.Entity<Request>()
.HasOne(r => r.Withdrawal)
.WithOne(w => w.Request)
.HasForeignKey<Withdrawal>(t => t.RequestId)
.IsRequired(false);
modelBuilder.Entity<Transfer>()
.HasOne(t => t.SenderAccount)
.WithMany(a => a.SenderTransfers)
.HasForeignKey(t => t.SenderAccountId).OnDelete(DeleteBehavior.Restrict);

View File

@ -0,0 +1,468 @@
// <auto-generated />
using System;
using BankDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BankDatabaseImplement.Migrations
{
[DbContext(typeof(BankDatabase))]
[Migration("20240504190530_Migration2")]
partial class Migration2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.17")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("BankDatabaseImplement.Models.Account", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ManagerId")
.HasColumnType("int");
b.Property<int>("Money")
.HasColumnType("int");
b.Property<string>("Number")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ReleaseDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("ManagerId");
b.ToTable("Accounts");
});
modelBuilder.Entity("BankDatabaseImplement.Models.AccountWithdrawal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AccountId")
.HasColumnType("int");
b.Property<int>("Sum")
.HasColumnType("int");
b.Property<int>("WithdrawalId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AccountId");
b.HasIndex("WithdrawalId");
b.ToTable("AccountWithdrawals");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Card", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<string>("Cvv")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ExpirationDate")
.HasColumnType("datetime2");
b.Property<string>("Number")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Pin")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ReleaseDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Cards");
});
modelBuilder.Entity("BankDatabaseImplement.Models.CardRequest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CardId")
.HasColumnType("int");
b.Property<int>("RequestId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CardId");
b.HasIndex("RequestId");
b.ToTable("CardRequests");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Manager", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Managers");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("OperationId")
.HasColumnType("int");
b.Property<DateTime>("OperationTime")
.HasColumnType("datetime2");
b.Property<int>("RecipientCardId")
.HasColumnType("int");
b.Property<int?>("SenderCardId")
.IsRequired()
.HasColumnType("int");
b.Property<int>("Sum")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RecipientCardId");
b.HasIndex("SenderCardId");
b.ToTable("Operations");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Request", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("RequestId")
.HasColumnType("int");
b.Property<DateTime>("RequestTime")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<int>("Sum")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Requests");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("OperationId")
.HasColumnType("int");
b.Property<int>("RecipientAccountId")
.HasColumnType("int");
b.Property<int>("SenderAccountId")
.HasColumnType("int");
b.Property<int>("Sum")
.HasColumnType("int");
b.Property<DateTime>("TransferTime")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("OperationId")
.IsUnique()
.HasFilter("[OperationId] IS NOT NULL");
b.HasIndex("RecipientAccountId");
b.HasIndex("SenderAccountId");
b.ToTable("Transfers");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("RequestId")
.HasColumnType("int");
b.Property<DateTime>("WithdrawalTime")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("RequestId")
.IsUnique()
.HasFilter("[RequestId] IS NOT NULL");
b.ToTable("Withdrawals");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Account", b =>
{
b.HasOne("BankDatabaseImplement.Models.Manager", "Manager")
.WithMany("Accounts")
.HasForeignKey("ManagerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Manager");
});
modelBuilder.Entity("BankDatabaseImplement.Models.AccountWithdrawal", b =>
{
b.HasOne("BankDatabaseImplement.Models.Account", "Account")
.WithMany("AccountWithdrawals")
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Withdrawal", "Withdrawal")
.WithMany("Accounts")
.HasForeignKey("WithdrawalId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Account");
b.Navigation("Withdrawal");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Card", b =>
{
b.HasOne("BankDatabaseImplement.Models.Client", "Client")
.WithMany("Cards")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("BankDatabaseImplement.Models.CardRequest", b =>
{
b.HasOne("BankDatabaseImplement.Models.Card", "Card")
.WithMany("CardRequests")
.HasForeignKey("CardId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Request", "Request")
.WithMany("Cards")
.HasForeignKey("RequestId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Card");
b.Navigation("Request");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b =>
{
b.HasOne("BankDatabaseImplement.Models.Card", "RecipientCard")
.WithMany("RecipientOperations")
.HasForeignKey("RecipientCardId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Card", "SenderCard")
.WithMany("SenderOperations")
.HasForeignKey("SenderCardId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("RecipientCard");
b.Navigation("SenderCard");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b =>
{
b.HasOne("BankDatabaseImplement.Models.Operation", "Operation")
.WithOne("Transfer")
.HasForeignKey("BankDatabaseImplement.Models.Transfer", "OperationId");
b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount")
.WithMany("RecipientTransfers")
.HasForeignKey("RecipientAccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Account", "SenderAccount")
.WithMany("SenderTransfers")
.HasForeignKey("SenderAccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Operation");
b.Navigation("RecipientAccount");
b.Navigation("SenderAccount");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>
{
b.HasOne("BankDatabaseImplement.Models.Request", "Request")
.WithOne("Withdrawal")
.HasForeignKey("BankDatabaseImplement.Models.Withdrawal", "RequestId");
b.Navigation("Request");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Account", b =>
{
b.Navigation("AccountWithdrawals");
b.Navigation("RecipientTransfers");
b.Navigation("SenderTransfers");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Card", b =>
{
b.Navigation("CardRequests");
b.Navigation("RecipientOperations");
b.Navigation("SenderOperations");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Client", b =>
{
b.Navigation("Cards");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Manager", b =>
{
b.Navigation("Accounts");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b =>
{
b.Navigation("Transfer");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Request", b =>
{
b.Navigation("Cards");
b.Navigation("Withdrawal");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>
{
b.Navigation("Accounts");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,160 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BankDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Migration2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Transfers_Operations_OperationId",
table: "Transfers");
migrationBuilder.DropForeignKey(
name: "FK_Withdrawals_Requests_RequestId",
table: "Withdrawals");
migrationBuilder.DropIndex(
name: "IX_Withdrawals_RequestId",
table: "Withdrawals");
migrationBuilder.DropIndex(
name: "IX_Transfers_OperationId",
table: "Transfers");
migrationBuilder.AlterColumn<int>(
name: "RequestId",
table: "Withdrawals",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<int>(
name: "OperationId",
table: "Transfers",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AddColumn<int>(
name: "RequestId",
table: "Requests",
type: "int",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "OperationId",
table: "Operations",
type: "int",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Withdrawals_RequestId",
table: "Withdrawals",
column: "RequestId",
unique: true,
filter: "[RequestId] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_Transfers_OperationId",
table: "Transfers",
column: "OperationId",
unique: true,
filter: "[OperationId] IS NOT NULL");
migrationBuilder.AddForeignKey(
name: "FK_Transfers_Operations_OperationId",
table: "Transfers",
column: "OperationId",
principalTable: "Operations",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Withdrawals_Requests_RequestId",
table: "Withdrawals",
column: "RequestId",
principalTable: "Requests",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Transfers_Operations_OperationId",
table: "Transfers");
migrationBuilder.DropForeignKey(
name: "FK_Withdrawals_Requests_RequestId",
table: "Withdrawals");
migrationBuilder.DropIndex(
name: "IX_Withdrawals_RequestId",
table: "Withdrawals");
migrationBuilder.DropIndex(
name: "IX_Transfers_OperationId",
table: "Transfers");
migrationBuilder.DropColumn(
name: "RequestId",
table: "Requests");
migrationBuilder.DropColumn(
name: "OperationId",
table: "Operations");
migrationBuilder.AlterColumn<int>(
name: "RequestId",
table: "Withdrawals",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "OperationId",
table: "Transfers",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.CreateIndex(
name: "IX_Withdrawals_RequestId",
table: "Withdrawals",
column: "RequestId");
migrationBuilder.CreateIndex(
name: "IX_Transfers_OperationId",
table: "Transfers",
column: "OperationId");
migrationBuilder.AddForeignKey(
name: "FK_Transfers_Operations_OperationId",
table: "Transfers",
column: "OperationId",
principalTable: "Operations",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Withdrawals_Requests_RequestId",
table: "Withdrawals",
column: "RequestId",
principalTable: "Requests",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@ -0,0 +1,462 @@
// <auto-generated />
using System;
using BankDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BankDatabaseImplement.Migrations
{
[DbContext(typeof(BankDatabase))]
[Migration("20240504190836_Migration3")]
partial class Migration3
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.17")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("BankDatabaseImplement.Models.Account", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ManagerId")
.HasColumnType("int");
b.Property<int>("Money")
.HasColumnType("int");
b.Property<string>("Number")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ReleaseDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("ManagerId");
b.ToTable("Accounts");
});
modelBuilder.Entity("BankDatabaseImplement.Models.AccountWithdrawal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AccountId")
.HasColumnType("int");
b.Property<int>("Sum")
.HasColumnType("int");
b.Property<int>("WithdrawalId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AccountId");
b.HasIndex("WithdrawalId");
b.ToTable("AccountWithdrawals");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Card", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<string>("Cvv")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ExpirationDate")
.HasColumnType("datetime2");
b.Property<string>("Number")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Pin")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ReleaseDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Cards");
});
modelBuilder.Entity("BankDatabaseImplement.Models.CardRequest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CardId")
.HasColumnType("int");
b.Property<int>("RequestId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CardId");
b.HasIndex("RequestId");
b.ToTable("CardRequests");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Manager", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Fio")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Managers");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("OperationTime")
.HasColumnType("datetime2");
b.Property<int>("RecipientCardId")
.HasColumnType("int");
b.Property<int?>("SenderCardId")
.IsRequired()
.HasColumnType("int");
b.Property<int>("Sum")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RecipientCardId");
b.HasIndex("SenderCardId");
b.ToTable("Operations");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Request", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("RequestTime")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<int>("Sum")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Requests");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("OperationId")
.HasColumnType("int");
b.Property<int>("RecipientAccountId")
.HasColumnType("int");
b.Property<int>("SenderAccountId")
.HasColumnType("int");
b.Property<int>("Sum")
.HasColumnType("int");
b.Property<DateTime>("TransferTime")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("OperationId")
.IsUnique()
.HasFilter("[OperationId] IS NOT NULL");
b.HasIndex("RecipientAccountId");
b.HasIndex("SenderAccountId");
b.ToTable("Transfers");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("RequestId")
.HasColumnType("int");
b.Property<DateTime>("WithdrawalTime")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("RequestId")
.IsUnique()
.HasFilter("[RequestId] IS NOT NULL");
b.ToTable("Withdrawals");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Account", b =>
{
b.HasOne("BankDatabaseImplement.Models.Manager", "Manager")
.WithMany("Accounts")
.HasForeignKey("ManagerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Manager");
});
modelBuilder.Entity("BankDatabaseImplement.Models.AccountWithdrawal", b =>
{
b.HasOne("BankDatabaseImplement.Models.Account", "Account")
.WithMany("AccountWithdrawals")
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Withdrawal", "Withdrawal")
.WithMany("Accounts")
.HasForeignKey("WithdrawalId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Account");
b.Navigation("Withdrawal");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Card", b =>
{
b.HasOne("BankDatabaseImplement.Models.Client", "Client")
.WithMany("Cards")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("BankDatabaseImplement.Models.CardRequest", b =>
{
b.HasOne("BankDatabaseImplement.Models.Card", "Card")
.WithMany("CardRequests")
.HasForeignKey("CardId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Request", "Request")
.WithMany("Cards")
.HasForeignKey("RequestId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Card");
b.Navigation("Request");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b =>
{
b.HasOne("BankDatabaseImplement.Models.Card", "RecipientCard")
.WithMany("RecipientOperations")
.HasForeignKey("RecipientCardId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Card", "SenderCard")
.WithMany("SenderOperations")
.HasForeignKey("SenderCardId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("RecipientCard");
b.Navigation("SenderCard");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b =>
{
b.HasOne("BankDatabaseImplement.Models.Operation", "Operation")
.WithOne("Transfer")
.HasForeignKey("BankDatabaseImplement.Models.Transfer", "OperationId");
b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount")
.WithMany("RecipientTransfers")
.HasForeignKey("RecipientAccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("BankDatabaseImplement.Models.Account", "SenderAccount")
.WithMany("SenderTransfers")
.HasForeignKey("SenderAccountId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Operation");
b.Navigation("RecipientAccount");
b.Navigation("SenderAccount");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>
{
b.HasOne("BankDatabaseImplement.Models.Request", "Request")
.WithOne("Withdrawal")
.HasForeignKey("BankDatabaseImplement.Models.Withdrawal", "RequestId");
b.Navigation("Request");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Account", b =>
{
b.Navigation("AccountWithdrawals");
b.Navigation("RecipientTransfers");
b.Navigation("SenderTransfers");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Card", b =>
{
b.Navigation("CardRequests");
b.Navigation("RecipientOperations");
b.Navigation("SenderOperations");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Client", b =>
{
b.Navigation("Cards");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Manager", b =>
{
b.Navigation("Accounts");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b =>
{
b.Navigation("Transfer");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Request", b =>
{
b.Navigation("Cards");
b.Navigation("Withdrawal");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>
{
b.Navigation("Accounts");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BankDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Migration3 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "RequestId",
table: "Requests");
migrationBuilder.DropColumn(
name: "OperationId",
table: "Operations");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "RequestId",
table: "Requests",
type: "int",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "OperationId",
table: "Operations",
type: "int",
nullable: true);
}
}
}

View File

@ -246,7 +246,6 @@ namespace BankDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("OperationId")
.IsRequired()
.HasColumnType("int");
b.Property<int>("RecipientAccountId")
@ -263,7 +262,9 @@ namespace BankDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("OperationId");
b.HasIndex("OperationId")
.IsUnique()
.HasFilter("[OperationId] IS NOT NULL");
b.HasIndex("RecipientAccountId");
@ -281,7 +282,6 @@ namespace BankDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("RequestId")
.IsRequired()
.HasColumnType("int");
b.Property<DateTime>("WithdrawalTime")
@ -289,7 +289,9 @@ namespace BankDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("RequestId");
b.HasIndex("RequestId")
.IsUnique()
.HasFilter("[RequestId] IS NOT NULL");
b.ToTable("Withdrawals");
});
@ -376,10 +378,8 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b =>
{
b.HasOne("BankDatabaseImplement.Models.Operation", "Operation")
.WithMany()
.HasForeignKey("OperationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.WithOne("Transfer")
.HasForeignKey("BankDatabaseImplement.Models.Transfer", "OperationId");
b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount")
.WithMany("RecipientTransfers")
@ -403,10 +403,8 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>
{
b.HasOne("BankDatabaseImplement.Models.Request", "Request")
.WithMany()
.HasForeignKey("RequestId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.WithOne("Withdrawal")
.HasForeignKey("BankDatabaseImplement.Models.Withdrawal", "RequestId");
b.Navigation("Request");
});
@ -439,9 +437,16 @@ namespace BankDatabaseImplement.Migrations
b.Navigation("Accounts");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b =>
{
b.Navigation("Transfer");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Request", b =>
{
b.Navigation("Cards");
b.Navigation("Withdrawal");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b =>

View File

@ -25,7 +25,6 @@ namespace BankDatabaseImplement.Models
[Required]
public int RecipientCardId { get; set; }
public virtual Card? RecipientCard { get; private set; }
[ForeignKey("OperationId")]
public virtual Transfer? Transfer { get; private set; }
public static Operation? Create(OperationBindingModel model)

View File

@ -22,8 +22,6 @@ namespace BankDatabaseImplement.Models
public RequestStatus Status { get; set; }
[ForeignKey("RequestId")]
public virtual List<CardRequest> Cards { get; set; } = new();
[ForeignKey("RequestId")]
public virtual Withdrawal? Withdrawal { get; set; }
private Dictionary<int, ICardModel>? _cardRequests { get; set; } = null;
[NotMapped]