diff --git a/Bank/BankClientApp/Views/Home/RequestCreate.cshtml b/Bank/BankClientApp/Views/Home/RequestCreate.cshtml index 32a3e4c..07b1a9d 100644 --- a/Bank/BankClientApp/Views/Home/RequestCreate.cshtml +++ b/Bank/BankClientApp/Views/Home/RequestCreate.cshtml @@ -1,8 +1,8 @@ @{ - ViewData["Title"] = "CardCreate"; + ViewData["Title"] = "RequestCreate"; }
-

Создание карты

+

Создание заапроса

diff --git a/Bank/BankContracts/BindingModels/CardBindingModel.cs b/Bank/BankContracts/BindingModels/CardBindingModel.cs index 8b0b8c1..e65e985 100644 --- a/Bank/BankContracts/BindingModels/CardBindingModel.cs +++ b/Bank/BankContracts/BindingModels/CardBindingModel.cs @@ -16,6 +16,5 @@ namespace BankContracts.BindingModels public DateTime ReleaseDate { get; set; } public DateTime ExpirationDate { get; set; } public int ClientId { get; set; } - public int? AccountId { get; set; } } } diff --git a/Bank/BankDataModels/Models/ICardModel.cs b/Bank/BankDataModels/Models/ICardModel.cs index d603e5f..7555578 100644 --- a/Bank/BankDataModels/Models/ICardModel.cs +++ b/Bank/BankDataModels/Models/ICardModel.cs @@ -14,6 +14,5 @@ namespace BankDataModels.Models DateTime ReleaseDate { get; set; } DateTime ExpirationDate { get; set; } int ClientId { get; set; } - int? AccountId { get; set; } } } diff --git a/Bank/BankDatabaseImplement/Implements/CardStorage.cs b/Bank/BankDatabaseImplement/Implements/CardStorage.cs index 37c76e4..aa925ae 100644 --- a/Bank/BankDatabaseImplement/Implements/CardStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/CardStorage.cs @@ -12,14 +12,14 @@ namespace BankDatabaseImplement.Implements public List GetFullList() { using var context = new BankDatabase(); - return context.Cards.Include(x => x.Client).Include(x => x.Account).Include(x => x.CardRequests) + return context.Cards.Include(x => x.Client).Include(x => x.CardRequests) .Include(x => x.SenderOperations).Include(x => x.RecipientOperations) .Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(CardSearchModel model) { using var context = new BankDatabase(); - return context.Cards.Include(x => x.Client).Include(x => x.Account).Include(x => x.CardRequests) + return context.Cards.Include(x => x.Client).Include(x => x.CardRequests) .Include(x => x.SenderOperations).Include(x => x.RecipientOperations) .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) && @@ -32,7 +32,7 @@ namespace BankDatabaseImplement.Implements public CardViewModel? GetElement(CardSearchModel model) { using var context = new BankDatabase(); - return context.Cards.Include(x => x.Client).Include(x => x.Account).Include(x => x.CardRequests) + return context.Cards.Include(x => x.Client).Include(x => x.CardRequests) .Include(x => x.SenderOperations).Include(x => x.RecipientOperations).FirstOrDefault( x => ((!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Number) || x.Number == model.Number)) @@ -53,7 +53,7 @@ namespace BankDatabaseImplement.Implements public CardViewModel? Update(CardBindingModel model) { using var context = new BankDatabase(); - var card = context.Cards.Include(x => x.Client).Include(x => x.Account).Include(x => x.CardRequests) + var card = context.Cards.Include(x => x.Client).Include(x => x.CardRequests) .Include(x => x.SenderOperations).Include(x => x.RecipientOperations).FirstOrDefault(x => x.Id == model.Id); if (card == null) { @@ -66,7 +66,7 @@ namespace BankDatabaseImplement.Implements public CardViewModel? Delete(CardBindingModel model) { using var context = new BankDatabase(); - var card = context.Cards.Include(x => x.Client).Include(x => x.Account).Include(x => x.CardRequests) + var card = context.Cards.Include(x => x.Client).Include(x => x.CardRequests) .Include(x => x.SenderOperations).Include(x => x.RecipientOperations).FirstOrDefault(rec => rec.Id == model.Id); if (card != null) { diff --git a/Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.Designer.cs b/Bank/BankDatabaseImplement/Migrations/20240502121513_InitialCreate.Designer.cs similarity index 96% rename from Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.Designer.cs rename to Bank/BankDatabaseImplement/Migrations/20240502121513_InitialCreate.Designer.cs index 05ecd1a..75f4bf4 100644 --- a/Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.Designer.cs +++ b/Bank/BankDatabaseImplement/Migrations/20240502121513_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BankDatabaseImplement.Migrations { [DbContext(typeof(BankDatabase))] - [Migration("20240429095730_InitialCreate")] + [Migration("20240502121513_InitialCreate")] partial class InitialCreate { /// @@ -87,9 +87,6 @@ namespace BankDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("AccountId") - .HasColumnType("int"); - b.Property("ClientId") .HasColumnType("int"); @@ -113,8 +110,6 @@ namespace BankDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("AccountId"); - b.HasIndex("ClientId"); b.ToTable("Cards"); @@ -134,9 +129,6 @@ namespace BankDatabaseImplement.Migrations b.Property("RequestId") .HasColumnType("int"); - b.Property("Sum") - .HasColumnType("int"); - b.HasKey("Id"); b.HasIndex("CardId"); @@ -337,18 +329,12 @@ namespace BankDatabaseImplement.Migrations modelBuilder.Entity("BankDatabaseImplement.Models.Card", b => { - b.HasOne("BankDatabaseImplement.Models.Account", "Account") - .WithMany() - .HasForeignKey("AccountId"); - b.HasOne("BankDatabaseImplement.Models.Client", "Client") .WithMany("Cards") .HasForeignKey("ClientId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("Account"); - b.Navigation("Client"); }); diff --git a/Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.cs b/Bank/BankDatabaseImplement/Migrations/20240502121513_InitialCreate.cs similarity index 96% rename from Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.cs rename to Bank/BankDatabaseImplement/Migrations/20240502121513_InitialCreate.cs index dd7c592..8481303 100644 --- a/Bank/BankDatabaseImplement/Migrations/20240429095730_InitialCreate.cs +++ b/Bank/BankDatabaseImplement/Migrations/20240502121513_InitialCreate.cs @@ -56,6 +56,30 @@ namespace BankDatabaseImplement.Migrations table.PrimaryKey("PK_Requests", x => x.Id); }); + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_Cards", x => x.Id); + table.ForeignKey( + name: "FK_Cards_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "Accounts", columns: table => new @@ -98,63 +122,6 @@ namespace BankDatabaseImplement.Migrations 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: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Cards", x => x.Id); - table.ForeignKey( - name: "FK_Cards_Accounts_AccountId", - column: x => x.AccountId, - principalTable: "Accounts", - principalColumn: "Id"); - 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 @@ -162,8 +129,7 @@ namespace BankDatabaseImplement.Migrations 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) + RequestId = table.Column(type: "int", nullable: false) }, constraints: table => { @@ -210,6 +176,33 @@ namespace BankDatabaseImplement.Migrations onDelete: ReferentialAction.Restrict); }); + 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: "Transfers", columns: table => new @@ -270,11 +263,6 @@ namespace BankDatabaseImplement.Migrations table: "CardRequests", column: "RequestId"); - migrationBuilder.CreateIndex( - name: "IX_Cards_AccountId", - table: "Cards", - column: "AccountId"); - migrationBuilder.CreateIndex( name: "IX_Cards_ClientId", table: "Cards", @@ -326,23 +314,23 @@ namespace BankDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Withdrawals"); + migrationBuilder.DropTable( + name: "Accounts"); + migrationBuilder.DropTable( name: "Operations"); migrationBuilder.DropTable( name: "Requests"); + migrationBuilder.DropTable( + name: "Managers"); + 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 index ba56066..7479a2c 100644 --- a/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs +++ b/Bank/BankDatabaseImplement/Migrations/BankDatabaseModelSnapshot.cs @@ -84,9 +84,6 @@ namespace BankDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("AccountId") - .HasColumnType("int"); - b.Property("ClientId") .HasColumnType("int"); @@ -110,8 +107,6 @@ namespace BankDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("AccountId"); - b.HasIndex("ClientId"); b.ToTable("Cards"); @@ -131,9 +126,6 @@ namespace BankDatabaseImplement.Migrations b.Property("RequestId") .HasColumnType("int"); - b.Property("Sum") - .HasColumnType("int"); - b.HasKey("Id"); b.HasIndex("CardId"); @@ -334,18 +326,12 @@ namespace BankDatabaseImplement.Migrations modelBuilder.Entity("BankDatabaseImplement.Models.Card", b => { - b.HasOne("BankDatabaseImplement.Models.Account", "Account") - .WithMany() - .HasForeignKey("AccountId"); - b.HasOne("BankDatabaseImplement.Models.Client", "Client") .WithMany("Cards") .HasForeignKey("ClientId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("Account"); - b.Navigation("Client"); }); diff --git a/Bank/BankDatabaseImplement/Models/Card.cs b/Bank/BankDatabaseImplement/Models/Card.cs index 1c600ee..badd3ed 100644 --- a/Bank/BankDatabaseImplement/Models/Card.cs +++ b/Bank/BankDatabaseImplement/Models/Card.cs @@ -29,8 +29,7 @@ namespace BankDatabaseImplement.Models [Required] public int ClientId { get; set; } public virtual Client? Client { get; private set; } - public int? AccountId { get; set; } = null; - public virtual Account? Account { get; private set; } + [ForeignKey("CardId")] public virtual List CardRequests { get; set; } = new(); [ForeignKey("SenderCardId"), DeleteBehavior(DeleteBehavior.Restrict)] @@ -50,7 +49,6 @@ namespace BankDatabaseImplement.Models ReleaseDate = DateTime.Now, ExpirationDate = DateTime.Now.AddYears(3), ClientId = model.ClientId, - AccountId = model.AccountId, }; } @@ -63,7 +61,6 @@ namespace BankDatabaseImplement.Models ReleaseDate = model.ReleaseDate; ExpirationDate = model.ExpirationDate; ClientId = model.ClientId; - AccountId = model.AccountId; } public CardViewModel GetViewModel => new() @@ -75,9 +72,7 @@ namespace BankDatabaseImplement.Models ReleaseDate = ReleaseDate, ExpirationDate = ExpirationDate, ClientId = ClientId, - AccountId = AccountId, ClientName = Client?.Fio ?? string.Empty, - AccountNumber = Account?.Number ?? string.Empty, }; } }