Еще фиксы
This commit is contained in:
parent
b5647466b4
commit
ad6cef2ed1
@ -1,8 +1,8 @@
|
||||
@{
|
||||
ViewData["Title"] = "CardCreate";
|
||||
ViewData["Title"] = "RequestCreate";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание карты</h2>
|
||||
<h2 class="display-4">Создание заапроса</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,5 @@ namespace BankDataModels.Models
|
||||
DateTime ReleaseDate { get; set; }
|
||||
DateTime ExpirationDate { get; set; }
|
||||
int ClientId { get; set; }
|
||||
int? AccountId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ namespace BankDatabaseImplement.Implements
|
||||
public List<CardViewModel> 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<CardViewModel> 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)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace BankDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(BankDatabase))]
|
||||
[Migration("20240429095730_InitialCreate")]
|
||||
[Migration("20240502121513_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -87,9 +87,6 @@ namespace BankDatabaseImplement.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("AccountId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("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<int>("RequestId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("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");
|
||||
});
|
||||
|
@ -56,6 +56,30 @@ namespace BankDatabaseImplement.Migrations
|
||||
table.PrimaryKey("PK_Requests", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Cards",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Number = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cvv = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Pin = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
ReleaseDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ExpirationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ClientId = table.Column<int>(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<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Number = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cvv = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Pin = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
ReleaseDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ExpirationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: false),
|
||||
AccountId = table.Column<int>(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<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
AccountId = table.Column<int>(type: "int", nullable: false),
|
||||
WithdrawalId = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<int>(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<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
CardId = table.Column<int>(type: "int", nullable: false),
|
||||
RequestId = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<int>(type: "int", nullable: false)
|
||||
RequestId = table.Column<int>(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<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
AccountId = table.Column<int>(type: "int", nullable: false),
|
||||
WithdrawalId = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<int>(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");
|
||||
}
|
||||
}
|
||||
}
|
@ -84,9 +84,6 @@ namespace BankDatabaseImplement.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("AccountId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("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<int>("RequestId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("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");
|
||||
});
|
||||
|
||||
|
@ -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<CardRequest> 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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user