diff --git a/Bank/BankContracts/BindingModels/AccountBindingModel.cs b/Bank/BankContracts/BindingModels/AccountBindingModel.cs index b2bab64..d15f625 100644 --- a/Bank/BankContracts/BindingModels/AccountBindingModel.cs +++ b/Bank/BankContracts/BindingModels/AccountBindingModel.cs @@ -12,7 +12,7 @@ namespace BankContracts.BindingModels public int Id { get; set; } public string Number { get; set; } = string.Empty; public int Money { get; set; } - public DateOnly ReleaseDate { get; set; } = DateOnly.FromDateTime(DateTime.Now); + public DateTime ReleaseDate { get; set; } = DateTime.Now; public int ManagerId { get; set; } } } diff --git a/Bank/BankContracts/BindingModels/CardBindingModel.cs b/Bank/BankContracts/BindingModels/CardBindingModel.cs index f3f40c2..8b0b8c1 100644 --- a/Bank/BankContracts/BindingModels/CardBindingModel.cs +++ b/Bank/BankContracts/BindingModels/CardBindingModel.cs @@ -13,8 +13,8 @@ namespace BankContracts.BindingModels public string Number { get; set; } = string.Empty; public string Cvv { get; set; } = string.Empty; public string Pin { get; set; } = string.Empty; - public DateOnly ReleaseDate { get; set; } - public DateOnly ExpirationDate { get; set; } + public DateTime ReleaseDate { get; set; } + public DateTime ExpirationDate { get; set; } public int ClientId { get; set; } public int? AccountId { get; set; } } diff --git a/Bank/BankContracts/SearchModels/AccountSearchModel.cs b/Bank/BankContracts/SearchModels/AccountSearchModel.cs index e4553b4..220bcf2 100644 --- a/Bank/BankContracts/SearchModels/AccountSearchModel.cs +++ b/Bank/BankContracts/SearchModels/AccountSearchModel.cs @@ -10,7 +10,7 @@ namespace BankContracts.SearchModels { public int? Id { get; set; } public string? Number { get; set; } - public DateOnly? ReleaseDate { get; set; } + public DateTime? ReleaseDate { get; set; } public int? ManagerId { get; set; } } } diff --git a/Bank/BankContracts/SearchModels/CardSearchModel.cs b/Bank/BankContracts/SearchModels/CardSearchModel.cs index bc04b3e..00c86d1 100644 --- a/Bank/BankContracts/SearchModels/CardSearchModel.cs +++ b/Bank/BankContracts/SearchModels/CardSearchModel.cs @@ -11,7 +11,7 @@ namespace BankContracts.SearchModels public int? Id { get; set; } public string? Number { get; set; } public int? ClientId { get; set; } - public DateOnly? ReleaseDate { get; set; } - public DateOnly? ExpirationDate { get; set; } + public DateTime? ReleaseDate { get; set; } + public DateTime? ExpirationDate { get; set; } } } diff --git a/Bank/BankContracts/ViewModels/AccountViewModel.cs b/Bank/BankContracts/ViewModels/AccountViewModel.cs index 3cb1db1..21f9213 100644 --- a/Bank/BankContracts/ViewModels/AccountViewModel.cs +++ b/Bank/BankContracts/ViewModels/AccountViewModel.cs @@ -16,7 +16,7 @@ namespace BankContracts.ViewModels [DisplayName("Деньги на счёте")] public int Money { get; set; } [DisplayName("Дата открытия")] - public DateOnly ReleaseDate { get; set; } = DateOnly.FromDateTime(DateTime.Now); + public DateTime ReleaseDate { get; set; } = DateTime.Now; [DisplayName("Менеджер")] public string ManagerName { get; set; } = string.Empty; public int ManagerId { get; set; } diff --git a/Bank/BankContracts/ViewModels/CardViewModel.cs b/Bank/BankContracts/ViewModels/CardViewModel.cs index 784712b..df13f97 100644 --- a/Bank/BankContracts/ViewModels/CardViewModel.cs +++ b/Bank/BankContracts/ViewModels/CardViewModel.cs @@ -18,9 +18,9 @@ namespace BankContracts.ViewModels [DisplayName("PIN-код")] public string Pin { get; set; } = string.Empty; [DisplayName("Дата выпуска")] - public DateOnly ReleaseDate { get; set; } + public DateTime ReleaseDate { get; set; } [DisplayName("Дата окончания действия")] - public DateOnly ExpirationDate { get; set; } + public DateTime ExpirationDate { get; set; } public int ClientId { get; set; } [DisplayName("Держатель карты")] public string ClientName { get; set; } = string.Empty; diff --git a/Bank/BankDataModels/Models/IAccountModel.cs b/Bank/BankDataModels/Models/IAccountModel.cs index cde7653..1f44889 100644 --- a/Bank/BankDataModels/Models/IAccountModel.cs +++ b/Bank/BankDataModels/Models/IAccountModel.cs @@ -10,7 +10,7 @@ namespace BankDataModels.Models { string Number { get; set; } int Money { get; set; } - DateOnly ReleaseDate { get; set; } + DateTime ReleaseDate { get; set; } int ManagerId { get; set; } } } diff --git a/Bank/BankDataModels/Models/ICardModel.cs b/Bank/BankDataModels/Models/ICardModel.cs index acdd6ef..d603e5f 100644 --- a/Bank/BankDataModels/Models/ICardModel.cs +++ b/Bank/BankDataModels/Models/ICardModel.cs @@ -11,8 +11,8 @@ namespace BankDataModels.Models string Number { get; set; } string Cvv { get; set; } string Pin { get; set; } - DateOnly ReleaseDate { get; set; } - DateOnly ExpirationDate { get; set; } + DateTime ReleaseDate { get; set; } + DateTime ExpirationDate { get; set; } int ClientId { get; set; } int? AccountId { get; set; } } diff --git a/Bank/BankDatabaseImplement/BankDatabase.cs b/Bank/BankDatabaseImplement/BankDatabase.cs index b9cfb0a..099503d 100644 --- a/Bank/BankDatabaseImplement/BankDatabase.cs +++ b/Bank/BankDatabaseImplement/BankDatabase.cs @@ -15,6 +15,27 @@ namespace BankDatabaseImplement base.OnConfiguring(optionsBuilder); } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasOne(t => t.SenderAccount) + .WithMany(a => a.SenderTransfers) + .HasForeignKey(t => t.SenderAccountId); + modelBuilder.Entity() + .HasOne(t => t.RecipientAccount) + .WithMany(a => a.RecipientTransfers) + .HasForeignKey(t => t.RecipientAccountId); + modelBuilder.Entity() + .HasOne(t => t.SenderCard) + .WithMany(a => a.SenderOperations) + .HasForeignKey(t => t.SenderCardId); + modelBuilder.Entity() + .HasOne(t => t.RecipientCard) + .WithMany(a => a.RecipientOperations) + .HasForeignKey(t => t.RecipientCardId); + base.OnModelCreating(modelBuilder); + } + public virtual DbSet Clients { get; set; } public virtual DbSet Cards { get; set; } public virtual DbSet Operations { get; set; } diff --git a/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.Designer.cs b/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.Designer.cs new file mode 100644 index 0000000..edc8afa --- /dev/null +++ b/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.Designer.cs @@ -0,0 +1,474 @@ +// +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("20240429090634_InitialCreate")] + partial class InitialCreate + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManagerId") + .HasColumnType("int"); + + b.Property("Money") + .HasColumnType("int"); + + b.Property("Number") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReleaseDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("ManagerId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.AccountWithdrawal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.Property("WithdrawalId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.HasIndex("WithdrawalId"); + + b.ToTable("AccountWithdrawals"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Card", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .IsRequired() + .HasColumnType("int"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Cvv") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExpirationDate") + .HasColumnType("datetime2"); + + b.Property("Number") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Pin") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReleaseDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.HasIndex("ClientId"); + + b.ToTable("Cards"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.CardRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CardId") + .HasColumnType("int"); + + b.Property("RequestId") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CardId"); + + b.HasIndex("RequestId"); + + b.ToTable("CardRequests"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Manager", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Managers"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OperationTime") + .HasColumnType("datetime2"); + + b.Property("RecipientCardId") + .HasColumnType("int"); + + b.Property("SenderCardId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RecipientCardId"); + + b.HasIndex("SenderCardId"); + + b.ToTable("Operations"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Request", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("RequestTime") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OperationId") + .IsRequired() + .HasColumnType("int"); + + b.Property("RecipientAccountId") + .HasColumnType("int"); + + b.Property("SenderAccountId") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.Property("TransferTime") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("OperationId"); + + b.HasIndex("RecipientAccountId"); + + b.HasIndex("SenderAccountId"); + + b.ToTable("Transfers"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("RequestId") + .IsRequired() + .HasColumnType("int"); + + b.Property("WithdrawalTime") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("RequestId"); + + 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.Account", "Account") + .WithMany() + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BankDatabaseImplement.Models.Client", "Client") + .WithMany("Cards") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + + 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.Cascade) + .IsRequired(); + + b.HasOne("BankDatabaseImplement.Models.Card", "SenderCard") + .WithMany("SenderOperations") + .HasForeignKey("SenderCardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("RecipientCard"); + + b.Navigation("SenderCard"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b => + { + b.HasOne("BankDatabaseImplement.Models.Operation", "Operation") + .WithMany() + .HasForeignKey("OperationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount") + .WithMany("RecipientTransfers") + .HasForeignKey("RecipientAccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BankDatabaseImplement.Models.Account", "SenderAccount") + .WithMany("SenderTransfers") + .HasForeignKey("SenderAccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Operation"); + + b.Navigation("RecipientAccount"); + + b.Navigation("SenderAccount"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b => + { + b.HasOne("BankDatabaseImplement.Models.Request", "Request") + .WithMany() + .HasForeignKey("RequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + 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.Request", b => + { + b.Navigation("Cards"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b => + { + b.Navigation("Accounts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.cs b/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.cs new file mode 100644 index 0000000..f9799b6 --- /dev/null +++ b/Bank/BankDatabaseImplement/Migrations/20240429090634_InitialCreate.cs @@ -0,0 +1,349 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BankDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Fio = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Managers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Fio = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Managers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Requests", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Sum = table.Column(type: "int", nullable: false), + RequestTime = table.Column(type: "datetime2", nullable: false), + Status = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Requests", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Accounts", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Number = table.Column(type: "nvarchar(max)", nullable: false), + Money = table.Column(type: "int", nullable: false), + ReleaseDate = table.Column(type: "datetime2", nullable: false), + ManagerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Accounts", x => x.Id); + table.ForeignKey( + name: "FK_Accounts_Managers_ManagerId", + column: x => x.ManagerId, + principalTable: "Managers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Withdrawals", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + WithdrawalTime = table.Column(type: "datetime2", nullable: false), + RequestId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Withdrawals", x => x.Id); + table.ForeignKey( + name: "FK_Withdrawals_Requests_RequestId", + column: x => x.RequestId, + principalTable: "Requests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Cards", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Number = table.Column(type: "nvarchar(max)", nullable: false), + Cvv = table.Column(type: "nvarchar(max)", nullable: false), + Pin = table.Column(type: "nvarchar(max)", nullable: false), + ReleaseDate = table.Column(type: "datetime2", nullable: false), + ExpirationDate = table.Column(type: "datetime2", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + AccountId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cards", x => x.Id); + table.ForeignKey( + name: "FK_Cards_Accounts_AccountId", + column: x => x.AccountId, + principalTable: "Accounts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Cards_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AccountWithdrawals", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AccountId = table.Column(type: "int", nullable: false), + WithdrawalId = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AccountWithdrawals", x => x.Id); + table.ForeignKey( + name: "FK_AccountWithdrawals_Accounts_AccountId", + column: x => x.AccountId, + principalTable: "Accounts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AccountWithdrawals_Withdrawals_WithdrawalId", + column: x => x.WithdrawalId, + principalTable: "Withdrawals", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CardRequests", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CardId = table.Column(type: "int", nullable: false), + RequestId = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CardRequests", x => x.Id); + table.ForeignKey( + name: "FK_CardRequests_Cards_CardId", + column: x => x.CardId, + principalTable: "Cards", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CardRequests_Requests_RequestId", + column: x => x.RequestId, + principalTable: "Requests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Operations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Sum = table.Column(type: "int", nullable: false), + OperationTime = table.Column(type: "datetime2", nullable: false), + SenderCardId = table.Column(type: "int", nullable: false), + RecipientCardId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Operations", x => x.Id); + table.ForeignKey( + name: "FK_Operations_Cards_RecipientCardId", + column: x => x.RecipientCardId, + principalTable: "Cards", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Operations_Cards_SenderCardId", + column: x => x.SenderCardId, + principalTable: "Cards", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Transfers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Sum = table.Column(type: "int", nullable: false), + TransferTime = table.Column(type: "datetime2", nullable: false), + OperationId = table.Column(type: "int", nullable: false), + SenderAccountId = table.Column(type: "int", nullable: false), + RecipientAccountId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Transfers", x => x.Id); + table.ForeignKey( + name: "FK_Transfers_Accounts_RecipientAccountId", + column: x => x.RecipientAccountId, + principalTable: "Accounts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Transfers_Accounts_SenderAccountId", + column: x => x.SenderAccountId, + principalTable: "Accounts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Transfers_Operations_OperationId", + column: x => x.OperationId, + principalTable: "Operations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Accounts_ManagerId", + table: "Accounts", + column: "ManagerId"); + + migrationBuilder.CreateIndex( + name: "IX_AccountWithdrawals_AccountId", + table: "AccountWithdrawals", + column: "AccountId"); + + migrationBuilder.CreateIndex( + name: "IX_AccountWithdrawals_WithdrawalId", + table: "AccountWithdrawals", + column: "WithdrawalId"); + + migrationBuilder.CreateIndex( + name: "IX_CardRequests_CardId", + table: "CardRequests", + column: "CardId"); + + migrationBuilder.CreateIndex( + name: "IX_CardRequests_RequestId", + table: "CardRequests", + column: "RequestId"); + + migrationBuilder.CreateIndex( + name: "IX_Cards_AccountId", + table: "Cards", + column: "AccountId"); + + migrationBuilder.CreateIndex( + name: "IX_Cards_ClientId", + table: "Cards", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Operations_RecipientCardId", + table: "Operations", + column: "RecipientCardId"); + + migrationBuilder.CreateIndex( + name: "IX_Operations_SenderCardId", + table: "Operations", + column: "SenderCardId"); + + migrationBuilder.CreateIndex( + name: "IX_Transfers_OperationId", + table: "Transfers", + column: "OperationId"); + + migrationBuilder.CreateIndex( + name: "IX_Transfers_RecipientAccountId", + table: "Transfers", + column: "RecipientAccountId"); + + migrationBuilder.CreateIndex( + name: "IX_Transfers_SenderAccountId", + table: "Transfers", + column: "SenderAccountId"); + + migrationBuilder.CreateIndex( + name: "IX_Withdrawals_RequestId", + table: "Withdrawals", + column: "RequestId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AccountWithdrawals"); + + migrationBuilder.DropTable( + name: "CardRequests"); + + migrationBuilder.DropTable( + name: "Transfers"); + + migrationBuilder.DropTable( + name: "Withdrawals"); + + migrationBuilder.DropTable( + name: "Operations"); + + migrationBuilder.DropTable( + name: "Requests"); + + migrationBuilder.DropTable( + name: "Cards"); + + migrationBuilder.DropTable( + name: "Accounts"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Managers"); + } + } +} diff --git a/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs b/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs new file mode 100644 index 0000000..15dea06 --- /dev/null +++ b/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs @@ -0,0 +1,471 @@ +// +using System; +using BankDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BankDatabaseImplement.Migrations +{ + [DbContext(typeof(BankDatabase))] + partial class BankDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManagerId") + .HasColumnType("int"); + + b.Property("Money") + .HasColumnType("int"); + + b.Property("Number") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReleaseDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("ManagerId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.AccountWithdrawal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.Property("WithdrawalId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.HasIndex("WithdrawalId"); + + b.ToTable("AccountWithdrawals"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Card", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AccountId") + .IsRequired() + .HasColumnType("int"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Cvv") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExpirationDate") + .HasColumnType("datetime2"); + + b.Property("Number") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Pin") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReleaseDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("AccountId"); + + b.HasIndex("ClientId"); + + b.ToTable("Cards"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.CardRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CardId") + .HasColumnType("int"); + + b.Property("RequestId") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CardId"); + + b.HasIndex("RequestId"); + + b.ToTable("CardRequests"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Manager", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Managers"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Operation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OperationTime") + .HasColumnType("datetime2"); + + b.Property("RecipientCardId") + .HasColumnType("int"); + + b.Property("SenderCardId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RecipientCardId"); + + b.HasIndex("SenderCardId"); + + b.ToTable("Operations"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Request", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("RequestTime") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("OperationId") + .IsRequired() + .HasColumnType("int"); + + b.Property("RecipientAccountId") + .HasColumnType("int"); + + b.Property("SenderAccountId") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("int"); + + b.Property("TransferTime") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("OperationId"); + + b.HasIndex("RecipientAccountId"); + + b.HasIndex("SenderAccountId"); + + b.ToTable("Transfers"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("RequestId") + .IsRequired() + .HasColumnType("int"); + + b.Property("WithdrawalTime") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("RequestId"); + + 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.Account", "Account") + .WithMany() + .HasForeignKey("AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BankDatabaseImplement.Models.Client", "Client") + .WithMany("Cards") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Account"); + + 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.Cascade) + .IsRequired(); + + b.HasOne("BankDatabaseImplement.Models.Card", "SenderCard") + .WithMany("SenderOperations") + .HasForeignKey("SenderCardId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("RecipientCard"); + + b.Navigation("SenderCard"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Transfer", b => + { + b.HasOne("BankDatabaseImplement.Models.Operation", "Operation") + .WithMany() + .HasForeignKey("OperationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BankDatabaseImplement.Models.Account", "RecipientAccount") + .WithMany("RecipientTransfers") + .HasForeignKey("RecipientAccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BankDatabaseImplement.Models.Account", "SenderAccount") + .WithMany("SenderTransfers") + .HasForeignKey("SenderAccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Operation"); + + b.Navigation("RecipientAccount"); + + b.Navigation("SenderAccount"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b => + { + b.HasOne("BankDatabaseImplement.Models.Request", "Request") + .WithMany() + .HasForeignKey("RequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + 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.Request", b => + { + b.Navigation("Cards"); + }); + + modelBuilder.Entity("BankDatabaseImplement.Models.Withdrawal", b => + { + b.Navigation("Accounts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Bank/BankDatabaseImplement/Models/Account.cs b/Bank/BankDatabaseImplement/Models/Account.cs index df2408f..5db3455 100644 --- a/Bank/BankDatabaseImplement/Models/Account.cs +++ b/Bank/BankDatabaseImplement/Models/Account.cs @@ -21,7 +21,7 @@ namespace BankDatabaseImplement.Models [Required] public int Money { get; set; } [Required] - public DateOnly ReleaseDate { get; set; } + public DateTime ReleaseDate { get; set; } [Required] public int ManagerId { get; set; } public virtual Manager? Manager { get; private set; } @@ -39,7 +39,7 @@ namespace BankDatabaseImplement.Models { Id = model.Id, Number = model.Number, - ReleaseDate = DateOnly.FromDateTime(DateTime.Now), + ReleaseDate = DateTime.Now, ManagerId = model.ManagerId, Money = 0, }; diff --git a/Bank/BankDatabaseImplement/Models/Card.cs b/Bank/BankDatabaseImplement/Models/Card.cs index 7135d13..d192feb 100644 --- a/Bank/BankDatabaseImplement/Models/Card.cs +++ b/Bank/BankDatabaseImplement/Models/Card.cs @@ -22,9 +22,9 @@ namespace BankDatabaseImplement.Models [Required] public string Pin { get; set; } = string.Empty; [Required] - public DateOnly ReleaseDate { get; set; } + public DateTime ReleaseDate { get; set; } [Required] - public DateOnly ExpirationDate { get; set; } + public DateTime ExpirationDate { get; set; } [Required] public int ClientId { get; set; } public virtual Client? Client { get; private set; } @@ -47,8 +47,8 @@ namespace BankDatabaseImplement.Models Number = model.Number, Cvv = model.Cvv, Pin = model.Pin, - ReleaseDate = DateOnly.FromDateTime(DateTime.Now), - ExpirationDate = DateOnly.FromDateTime(DateTime.Now).AddYears(3), + ReleaseDate = DateTime.Now, + ExpirationDate = DateTime.Now.AddYears(3), ClientId = model.ClientId, AccountId = model.AccountId, }; diff --git a/Bank/BankDatabaseImplement/Models/Transfer.cs b/Bank/BankDatabaseImplement/Models/Transfer.cs index 1d23d35..664d6ce 100644 --- a/Bank/BankDatabaseImplement/Models/Transfer.cs +++ b/Bank/BankDatabaseImplement/Models/Transfer.cs @@ -4,6 +4,7 @@ using BankDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -22,10 +23,10 @@ namespace BankDatabaseImplement.Models public virtual Operation? Operation { get; set; } = null; [Required] public int SenderAccountId { get; set; } - public virtual Account? SenderAccount { get; set; } + public virtual Account? SenderAccount { get; private set; } [Required] public int RecipientAccountId { get; set; } - public virtual Account? RecipientAccount { get; set; } + public virtual Account? RecipientAccount { get; private set; } public static Transfer? Create(TransferBindingModel model) {