конечно, мы все виноваты в этом ...

This commit is contained in:
DeerElk 2024-05-27 01:09:39 +04:00
parent dec9ceaf34
commit 8d73f33020
30 changed files with 178 additions and 396 deletions

View File

@ -51,7 +51,7 @@ namespace BankBusinessLogic.BusinessLogics
public List<ClientViewModel>? ReadList(ClientSearchModel? model) public List<ClientViewModel>? ReadList(ClientSearchModel? model)
{ {
_logger.LogInformation( _logger.LogInformation(
"ReadList. ClientSurname: {ClientSurname} {ClientName} " + "ReadList. ClientFullname: {ClientSurname} {ClientName} " +
"{ClientPatronomic}. Snils: {Snils}", model?.ClientSurname, "{ClientPatronomic}. Snils: {Snils}", model?.ClientSurname,
model?.ClientName, model?.ClientPatronymic, model?.Snils); model?.ClientName, model?.ClientPatronymic, model?.Snils);
var list = model == null ? _clientStorage.GetFullList() : var list = model == null ? _clientStorage.GetFullList() :

View File

@ -8,6 +8,8 @@ namespace BankContracts.ViewModels
[DisplayName("Идентификатор")] [DisplayName("Идентификатор")]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Идентификатор валюты")] [DisplayName("Идентификатор валюты")]
public int CurrencyId { get; set; }
[DisplayName("Название кредитной программы")]
public string ProgramName { get; set; } = string.Empty; public string ProgramName { get; set; } = string.Empty;
[DisplayName("Процентная ставка")] [DisplayName("Процентная ставка")]
public double InterestRate { get; set; } public double InterestRate { get; set; }

View File

@ -10,7 +10,5 @@
string? Email { get; } string? Email { get; }
string PasswordHash { get; } string PasswordHash { get; }
int WorkerId { get; } int WorkerId { get; }
Dictionary<int, IProgramModel> ClientPrograms { get; }
Dictionary<int, IDepositModel> ClientDeposits { get; }
} }
} }

View File

@ -2,9 +2,7 @@
{ {
public interface IDepositModel : IId public interface IDepositModel : IId
{ {
int WorkerId { get; }
double Sum { get; } double Sum { get; }
DateOnly OpeningDate { get; } DateOnly OpeningDate { get; }
Dictionary<int, ICurrencyModel> DepositCurrencies { get; }
} }
} }

View File

@ -4,6 +4,5 @@
{ {
string ProgramName { get; } string ProgramName { get; }
double InterestRate { get; } double InterestRate { get; }
Dictionary<int, ICurrencyModel> ProgramCurrencies { get; }
} }
} }

View File

@ -3,7 +3,6 @@
public interface IRefillModel : IId public interface IRefillModel : IId
{ {
int DepositId { get; } int DepositId { get; }
int WorkerId { get; }
double Sum { get; } double Sum { get; }
DateOnly RefillDate { get; } DateOnly RefillDate { get; }
} }

View File

@ -18,6 +18,14 @@ namespace BankDatabaseImplement
{ {
modelBuilder.Entity<Client>() modelBuilder.Entity<Client>()
.HasKey(c => c.Snils); .HasKey(c => c.Snils);
modelBuilder.Entity<ClientDeposit>()
.HasKey(sc => new { sc.ClientSnils, sc.DepositId });
modelBuilder.Entity<ClientProgram>()
.HasKey(sc => new { sc.ClientSnils, sc.ProgramId });
modelBuilder.Entity<DepositCurrency>()
.HasKey(sc => new { sc.DepositId, sc.CurrencyId });
modelBuilder.Entity<ProgramCurrency>()
.HasKey(sc => new { sc.ProgramId, sc.CurrencyId });
} }
public virtual DbSet<Client> Clients { set; get; } public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<ClientProgram> ClientPrograms { set; get; } public virtual DbSet<ClientProgram> ClientPrograms { set; get; }

View File

@ -12,7 +12,7 @@ namespace BankDatabaseImplement.Implements
public List<DepositViewModel> GetFullList() public List<DepositViewModel> GetFullList()
{ {
using var context = new BankDatabase(); using var context = new BankDatabase();
return context.Deposits.Include(x => x.Worker) return context.Deposits
.Select(x => x.GetViewModel).ToList(); .Select(x => x.GetViewModel).ToList();
} }
public List<DepositViewModel> GetFilteredList(DepositSearchModel model) public List<DepositViewModel> GetFilteredList(DepositSearchModel model)
@ -22,10 +22,8 @@ namespace BankDatabaseImplement.Implements
return new(); return new();
} }
using var context = new BankDatabase(); using var context = new BankDatabase();
return context.Deposits.Include(x => x.Worker) return context.Deposits
.Where(x => (model.WorkerId == 0 || .Where(x => (model.Sum == 0 || x.Sum == model.Sum))
x.WorkerId == model.WorkerId) &&
(model.Sum == 0 || x.Sum == model.Sum))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -36,10 +34,8 @@ namespace BankDatabaseImplement.Implements
return null; return null;
} }
using var context = new BankDatabase(); using var context = new BankDatabase();
return context.Deposits.Include(x => x.Worker) return context.Deposits
.FirstOrDefault(x => (model.WorkerId == 0 || .FirstOrDefault(x => (model.Sum == 0 || x.Sum == model.Sum) &&
x.WorkerId == model.WorkerId) &&
(model.Sum == 0 || x.Sum == model.Sum) &&
(!model.Id.HasValue || x.Id == model.Id)) (!model.Id.HasValue || x.Id == model.Id))
?.GetViewModel; ?.GetViewModel;
} }

View File

@ -13,7 +13,7 @@ namespace BankDatabaseImplement.Implements
{ {
using var context = new BankDatabase(); using var context = new BankDatabase();
return context.Refills.Include(x => x.Deposit) return context.Refills.Include(x => x.Deposit)
.Include(x => x.Worker).Select(x => x.GetViewModel).ToList(); .Select(x => x.GetViewModel).ToList();
} }
public List<RefillViewModel> GetFilteredList(RefillSearchModel model) public List<RefillViewModel> GetFilteredList(RefillSearchModel model)
{ {
@ -24,10 +24,8 @@ namespace BankDatabaseImplement.Implements
} }
using var context = new BankDatabase(); using var context = new BankDatabase();
return context.Refills.Include(x => x.Deposit) return context.Refills.Include(x => x.Deposit)
.Include(x => x.Worker)
.Where(x => (model.DepositId == 0 || .Where(x => (model.DepositId == 0 ||
x.DepositId == model.DepositId) && x.DepositId == model.DepositId) &&
(model.WorkerId == 0 || x.WorkerId == model.WorkerId) &&
(model.Sum == 0 || x.Sum == model.Sum) && (model.Sum == 0 || x.Sum == model.Sum) &&
(model.RefillDate == null || (model.RefillDate == null ||
x.RefillDate == model.RefillDate)) x.RefillDate == model.RefillDate))
@ -43,10 +41,8 @@ namespace BankDatabaseImplement.Implements
} }
using var context = new BankDatabase(); using var context = new BankDatabase();
return context.Refills.Include(x => x.Deposit) return context.Refills.Include(x => x.Deposit)
.Include(x => x.Worker)
.FirstOrDefault(x => (model.DepositId == 0 || .FirstOrDefault(x => (model.DepositId == 0 ||
x.DepositId == model.DepositId) && x.DepositId == model.DepositId) &&
(model.WorkerId == 0 || x.WorkerId == model.WorkerId) &&
(model.Sum == 0 || x.Sum == model.Sum) && (model.Sum == 0 || x.Sum == model.Sum) &&
(model.RefillDate == null || (model.RefillDate == null ||
x.RefillDate == model.RefillDate) && x.RefillDate == model.RefillDate) &&

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace BankDatabaseImplement.Migrations namespace BankDatabaseImplement.Migrations
{ {
[DbContext(typeof(BankDatabase))] [DbContext(typeof(BankDatabase))]
[Migration("20240502003921_InitialCreate")] [Migration("20240526202321_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -66,22 +66,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ClientDeposit", b => modelBuilder.Entity("BankDatabaseImplement.Models.ClientDeposit", b =>
{ {
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientSnils") b.Property<string>("ClientSnils")
.IsRequired()
.HasColumnType("nvarchar(450)"); .HasColumnType("nvarchar(450)");
b.Property<int>("DepositId") b.Property<int>("DepositId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("Id"); b.HasKey("ClientSnils", "DepositId");
b.HasIndex("ClientSnils");
b.HasIndex("DepositId"); b.HasIndex("DepositId");
@ -90,22 +81,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ClientProgram", b => modelBuilder.Entity("BankDatabaseImplement.Models.ClientProgram", b =>
{ {
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientSnils") b.Property<string>("ClientSnils")
.IsRequired()
.HasColumnType("nvarchar(450)"); .HasColumnType("nvarchar(450)");
b.Property<int>("ProgramId") b.Property<int>("ProgramId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("Id"); b.HasKey("ClientSnils", "ProgramId");
b.HasIndex("ClientSnils");
b.HasIndex("ProgramId"); b.HasIndex("ProgramId");
@ -158,24 +140,16 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.DepositCurrency", b => modelBuilder.Entity("BankDatabaseImplement.Models.DepositCurrency", b =>
{ {
b.Property<int>("Id") b.Property<int>("DepositId")
.ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CurrencyId") b.Property<int>("CurrencyId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("DepositId") b.HasKey("DepositId", "CurrencyId");
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CurrencyId"); b.HasIndex("CurrencyId");
b.HasIndex("DepositId");
b.ToTable("DepositCurrencies"); b.ToTable("DepositCurrencies");
}); });
@ -201,24 +175,16 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ProgramCurrency", b => modelBuilder.Entity("BankDatabaseImplement.Models.ProgramCurrency", b =>
{ {
b.Property<int>("Id") b.Property<int>("ProgramId")
.ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CurrencyId") b.Property<int>("CurrencyId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("ProgramId") b.HasKey("ProgramId", "CurrencyId");
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CurrencyId"); b.HasIndex("CurrencyId");
b.HasIndex("ProgramId");
b.ToTable("ProgramCurrencies"); b.ToTable("ProgramCurrencies");
}); });
@ -292,9 +258,6 @@ namespace BankDatabaseImplement.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<int?>("WorkerId")
.HasColumnType("int");
b.Property<string>("WorkerName") b.Property<string>("WorkerName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
@ -309,8 +272,6 @@ namespace BankDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("WorkerId");
b.ToTable("Workers"); b.ToTable("Workers");
}); });
@ -328,13 +289,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ClientDeposit", b => modelBuilder.Entity("BankDatabaseImplement.Models.ClientDeposit", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Client", "Client") b.HasOne("BankDatabaseImplement.Models.Client", "Client")
.WithMany("Deposits") .WithMany("ClientDeposits")
.HasForeignKey("ClientSnils") .HasForeignKey("ClientSnils")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("BankDatabaseImplement.Models.Deposit", "Deposit") b.HasOne("BankDatabaseImplement.Models.Deposit", "Deposit")
.WithMany("Clients") .WithMany("ClientDeposits")
.HasForeignKey("DepositId") .HasForeignKey("DepositId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -347,7 +308,7 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ClientProgram", b => modelBuilder.Entity("BankDatabaseImplement.Models.ClientProgram", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Client", "Client") b.HasOne("BankDatabaseImplement.Models.Client", "Client")
.WithMany("Programs") .WithMany("ClientPrograms")
.HasForeignKey("ClientSnils") .HasForeignKey("ClientSnils")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -366,7 +327,7 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.Deposit", b => modelBuilder.Entity("BankDatabaseImplement.Models.Deposit", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Worker", "Worker") b.HasOne("BankDatabaseImplement.Models.Worker", "Worker")
.WithMany() .WithMany("Deposits")
.HasForeignKey("WorkerId") .HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -377,13 +338,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.DepositCurrency", b => modelBuilder.Entity("BankDatabaseImplement.Models.DepositCurrency", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Currency", "Currency") b.HasOne("BankDatabaseImplement.Models.Currency", "Currency")
.WithMany("Deposits") .WithMany("DepositCurrencies")
.HasForeignKey("CurrencyId") .HasForeignKey("CurrencyId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("BankDatabaseImplement.Models.Deposit", "Deposit") b.HasOne("BankDatabaseImplement.Models.Deposit", "Deposit")
.WithMany("Currencies") .WithMany("DepositCurrencies")
.HasForeignKey("DepositId") .HasForeignKey("DepositId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -396,13 +357,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ProgramCurrency", b => modelBuilder.Entity("BankDatabaseImplement.Models.ProgramCurrency", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Currency", "Currency") b.HasOne("BankDatabaseImplement.Models.Currency", "Currency")
.WithMany("Programs") .WithMany("ProgramCurrencies")
.HasForeignKey("CurrencyId") .HasForeignKey("CurrencyId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("BankDatabaseImplement.Models.Program", "Program") b.HasOne("BankDatabaseImplement.Models.Program", "Program")
.WithMany("Currencies") .WithMany("ProgramCurrencies")
.HasForeignKey("ProgramId") .HasForeignKey("ProgramId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -421,7 +382,7 @@ namespace BankDatabaseImplement.Migrations
.IsRequired(); .IsRequired();
b.HasOne("BankDatabaseImplement.Models.Worker", "Worker") b.HasOne("BankDatabaseImplement.Models.Worker", "Worker")
.WithMany() .WithMany("Refills")
.HasForeignKey("WorkerId") .HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -442,32 +403,25 @@ namespace BankDatabaseImplement.Migrations
b.Navigation("Program"); b.Navigation("Program");
}); });
modelBuilder.Entity("BankDatabaseImplement.Models.Worker", b =>
{
b.HasOne("BankDatabaseImplement.Models.Worker", null)
.WithMany("Workers")
.HasForeignKey("WorkerId");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Client", b => modelBuilder.Entity("BankDatabaseImplement.Models.Client", b =>
{ {
b.Navigation("Deposits"); b.Navigation("ClientDeposits");
b.Navigation("Programs"); b.Navigation("ClientPrograms");
}); });
modelBuilder.Entity("BankDatabaseImplement.Models.Currency", b => modelBuilder.Entity("BankDatabaseImplement.Models.Currency", b =>
{ {
b.Navigation("Deposits"); b.Navigation("DepositCurrencies");
b.Navigation("Programs"); b.Navigation("ProgramCurrencies");
}); });
modelBuilder.Entity("BankDatabaseImplement.Models.Deposit", b => modelBuilder.Entity("BankDatabaseImplement.Models.Deposit", b =>
{ {
b.Navigation("Clients"); b.Navigation("ClientDeposits");
b.Navigation("Currencies"); b.Navigation("DepositCurrencies");
b.Navigation("Refills"); b.Navigation("Refills");
}); });
@ -476,14 +430,16 @@ namespace BankDatabaseImplement.Migrations
{ {
b.Navigation("Clients"); b.Navigation("Clients");
b.Navigation("Currencies"); b.Navigation("ProgramCurrencies");
b.Navigation("Terms"); b.Navigation("Terms");
}); });
modelBuilder.Entity("BankDatabaseImplement.Models.Worker", b => modelBuilder.Entity("BankDatabaseImplement.Models.Worker", b =>
{ {
b.Navigation("Workers"); b.Navigation("Deposits");
b.Navigation("Refills");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }

View File

@ -50,42 +50,37 @@ namespace BankDatabaseImplement.Migrations
WorkerPatronymic = table.Column<string>(type: "nvarchar(max)", nullable: false), WorkerPatronymic = table.Column<string>(type: "nvarchar(max)", nullable: false),
Phone = table.Column<string>(type: "nvarchar(max)", nullable: false), Phone = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false), Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: false), PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: false)
WorkerId = table.Column<int>(type: "int", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Workers", x => x.Id); table.PrimaryKey("PK_Workers", x => x.Id);
table.ForeignKey(
name: "FK_Workers_Workers_WorkerId",
column: x => x.WorkerId,
principalTable: "Workers",
principalColumn: "Id");
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "ProgramCurrencies", name: "ProgramCurrencies",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProgramId = table.Column<int>(type: "int", nullable: false), ProgramId = table.Column<int>(type: "int", nullable: false),
CurrencyId = table.Column<int>(type: "int", nullable: false) CurrencyId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_ProgramCurrencies", x => x.Id); table.PrimaryKey("PK_ProgramCurrencies", x => new { x.ProgramId, x.CurrencyId });
table.ForeignKey( table.ForeignKey(
name: "FK_ProgramCurrencies_Currencies_CurrencyId", name: "FK_ProgramCurrencies_Currencies_CurrencyId",
column: x => x.CurrencyId, column: x => x.CurrencyId,
principalTable: "Currencies", principalTable: "Currencies",
principalColumn: "Id"); principalColumn: "Id",
onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_ProgramCurrencies_Programs_ProgramId", name: "FK_ProgramCurrencies_Programs_ProgramId",
column: x => x.ProgramId, column: x => x.ProgramId,
principalTable: "Programs", principalTable: "Programs",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -94,8 +89,8 @@ namespace BankDatabaseImplement.Migrations
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
Duration = table.Column<int>(type: "int", nullable: false), ProgramId = table.Column<int>(type: "int", nullable: false),
ProgramId = table.Column<int>(type: "int", nullable: false) Duration = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
@ -105,14 +100,15 @@ namespace BankDatabaseImplement.Migrations
column: x => x.ProgramId, column: x => x.ProgramId,
principalTable: "Programs", principalTable: "Programs",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Clients", name: "Clients",
columns: table => new columns: table => new
{ {
Snils = table.Column<string>(type: "nvarchar(450)", nullable: false), Snils = table.Column<string>(type: "nvarchar(400)", nullable: false),
ClientSurname = table.Column<string>(type: "nvarchar(max)", nullable: false), ClientSurname = table.Column<string>(type: "nvarchar(max)", nullable: false),
ClientName = table.Column<string>(type: "nvarchar(max)", nullable: false), ClientName = table.Column<string>(type: "nvarchar(max)", nullable: false),
ClientPatronymic = table.Column<string>(type: "nvarchar(max)", nullable: false), ClientPatronymic = table.Column<string>(type: "nvarchar(max)", nullable: false),
@ -129,7 +125,8 @@ namespace BankDatabaseImplement.Migrations
column: x => x.WorkerId, column: x => x.WorkerId,
principalTable: "Workers", principalTable: "Workers",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Restrict,
onUpdate: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -138,93 +135,90 @@ namespace BankDatabaseImplement.Migrations
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
WorkerId = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false), Sum = table.Column<double>(type: "float", nullable: false),
OpeningDate = table.Column<DateOnly>(type: "date", nullable: false) OpeningDate = table.Column<DateOnly>(type: "date", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Deposits", x => x.Id); table.PrimaryKey("PK_Deposits", x => x.Id);
table.ForeignKey(
name: "FK_Deposits_Workers_WorkerId",
column: x => x.WorkerId,
principalTable: "Workers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "ClientPrograms", name: "ClientPrograms",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) ClientSnils = table.Column<string>(type: "nvarchar(400)", nullable: false),
.Annotation("SqlServer:Identity", "1, 1"),
ClientSnils = table.Column<string>(type: "nvarchar(450)", nullable: false),
ProgramId = table.Column<int>(type: "int", nullable: false) ProgramId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_ClientPrograms", x => x.Id); table.PrimaryKey("PK_ClientPrograms", x => new { x.ClientSnils, x.ProgramId });
table.ForeignKey( table.ForeignKey(
name: "FK_ClientPrograms_Clients_ClientSnils", name: "FK_ClientPrograms_Clients_ClientSnils",
column: x => x.ClientSnils, column: x => x.ClientSnils,
principalTable: "Clients", principalTable: "Clients",
principalColumn: "Snils", principalColumn: "Snils",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_ClientPrograms_Programs_ProgramId", name: "FK_ClientPrograms_Programs_ProgramId",
column: x => x.ProgramId, column: x => x.ProgramId,
principalTable: "Programs", principalTable: "Programs",
principalColumn: "Id"); principalColumn: "Id",
onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "ClientDeposits", name: "ClientDeposits",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) ClientSnils = table.Column<string>(type: "nvarchar(400)", nullable: false),
.Annotation("SqlServer:Identity", "1, 1"),
ClientSnils = table.Column<string>(type: "nvarchar(450)", nullable: false),
DepositId = table.Column<int>(type: "int", nullable: false) DepositId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_ClientDeposits", x => x.Id); table.PrimaryKey("PK_ClientDeposits", x => new { x.ClientSnils, x.DepositId });
table.ForeignKey( table.ForeignKey(
name: "FK_ClientDeposits_Clients_ClientSnils", name: "FK_ClientDeposits_Clients_ClientSnils",
column: x => x.ClientSnils, column: x => x.ClientSnils,
principalTable: "Clients", principalTable: "Clients",
principalColumn: "Snils", principalColumn: "Snils",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_ClientDeposits_Deposits_DepositId", name: "FK_ClientDeposits_Deposits_DepositId",
column: x => x.DepositId, column: x => x.DepositId,
principalTable: "Deposits"); principalTable: "Deposits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "DepositCurrencies", name: "DepositCurrencies",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DepositId = table.Column<int>(type: "int", nullable: false), DepositId = table.Column<int>(type: "int", nullable: false),
CurrencyId = table.Column<int>(type: "int", nullable: false) CurrencyId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_DepositCurrencies", x => x.Id); table.PrimaryKey("PK_DepositCurrencies", x => new { x.DepositId, x.CurrencyId });
table.ForeignKey( table.ForeignKey(
name: "FK_DepositCurrencies_Currencies_CurrencyId", name: "FK_DepositCurrencies_Currencies_CurrencyId",
column: x => x.CurrencyId, column: x => x.CurrencyId,
principalTable: "Currencies", principalTable: "Currencies",
principalColumn: "Id"); principalColumn: "Id",
onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_DepositCurrencies_Deposits_DepositId", name: "FK_DepositCurrencies_Deposits_DepositId",
column: x => x.DepositId, column: x => x.DepositId,
principalTable: "Deposits", principalTable: "Deposits",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade,
onUpdate: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -234,7 +228,6 @@ namespace BankDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
DepositId = table.Column<int>(type: "int", nullable: false), DepositId = table.Column<int>(type: "int", nullable: false),
WorkerId = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false), Sum = table.Column<double>(type: "float", nullable: false),
RefillDate = table.Column<DateOnly>(type: "date", nullable: false) RefillDate = table.Column<DateOnly>(type: "date", nullable: false)
}, },
@ -246,29 +239,15 @@ namespace BankDatabaseImplement.Migrations
column: x => x.DepositId, column: x => x.DepositId,
principalTable: "Deposits", principalTable: "Deposits",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade,
table.ForeignKey( onUpdate: ReferentialAction.Cascade);
name: "FK_Refills_Workers_WorkerId",
column: x => x.WorkerId,
principalTable: "Workers",
principalColumn: "Id");
}); });
migrationBuilder.CreateIndex(
name: "IX_ClientDeposits_ClientSnils",
table: "ClientDeposits",
column: "ClientSnils");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_ClientDeposits_DepositId", name: "IX_ClientDeposits_DepositId",
table: "ClientDeposits", table: "ClientDeposits",
column: "DepositId"); column: "DepositId");
migrationBuilder.CreateIndex(
name: "IX_ClientPrograms_ClientSnils",
table: "ClientPrograms",
column: "ClientSnils");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_ClientPrograms_ProgramId", name: "IX_ClientPrograms_ProgramId",
table: "ClientPrograms", table: "ClientPrograms",
@ -284,45 +263,20 @@ namespace BankDatabaseImplement.Migrations
table: "DepositCurrencies", table: "DepositCurrencies",
column: "CurrencyId"); column: "CurrencyId");
migrationBuilder.CreateIndex(
name: "IX_DepositCurrencies_DepositId",
table: "DepositCurrencies",
column: "DepositId");
migrationBuilder.CreateIndex(
name: "IX_Deposits_WorkerId",
table: "Deposits",
column: "WorkerId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_ProgramCurrencies_CurrencyId", name: "IX_ProgramCurrencies_CurrencyId",
table: "ProgramCurrencies", table: "ProgramCurrencies",
column: "CurrencyId"); column: "CurrencyId");
migrationBuilder.CreateIndex(
name: "IX_ProgramCurrencies_ProgramId",
table: "ProgramCurrencies",
column: "ProgramId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Refills_DepositId", name: "IX_Refills_DepositId",
table: "Refills", table: "Refills",
column: "DepositId"); column: "DepositId");
migrationBuilder.CreateIndex(
name: "IX_Refills_WorkerId",
table: "Refills",
column: "WorkerId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Terms_ProgramId", name: "IX_Terms_ProgramId",
table: "Terms", table: "Terms",
column: "ProgramId"); column: "ProgramId");
migrationBuilder.CreateIndex(
name: "IX_Workers_WorkerId",
table: "Workers",
column: "WorkerId");
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -63,22 +63,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ClientDeposit", b => modelBuilder.Entity("BankDatabaseImplement.Models.ClientDeposit", b =>
{ {
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientSnils") b.Property<string>("ClientSnils")
.IsRequired()
.HasColumnType("nvarchar(450)"); .HasColumnType("nvarchar(450)");
b.Property<int>("DepositId") b.Property<int>("DepositId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("Id"); b.HasKey("ClientSnils", "DepositId");
b.HasIndex("ClientSnils");
b.HasIndex("DepositId"); b.HasIndex("DepositId");
@ -87,22 +78,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ClientProgram", b => modelBuilder.Entity("BankDatabaseImplement.Models.ClientProgram", b =>
{ {
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientSnils") b.Property<string>("ClientSnils")
.IsRequired()
.HasColumnType("nvarchar(450)"); .HasColumnType("nvarchar(450)");
b.Property<int>("ProgramId") b.Property<int>("ProgramId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("Id"); b.HasKey("ClientSnils", "ProgramId");
b.HasIndex("ClientSnils");
b.HasIndex("ProgramId"); b.HasIndex("ProgramId");
@ -155,24 +137,16 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.DepositCurrency", b => modelBuilder.Entity("BankDatabaseImplement.Models.DepositCurrency", b =>
{ {
b.Property<int>("Id") b.Property<int>("DepositId")
.ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CurrencyId") b.Property<int>("CurrencyId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("DepositId") b.HasKey("DepositId", "CurrencyId");
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CurrencyId"); b.HasIndex("CurrencyId");
b.HasIndex("DepositId");
b.ToTable("DepositCurrencies"); b.ToTable("DepositCurrencies");
}); });
@ -198,24 +172,16 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ProgramCurrency", b => modelBuilder.Entity("BankDatabaseImplement.Models.ProgramCurrency", b =>
{ {
b.Property<int>("Id") b.Property<int>("ProgramId")
.ValueGeneratedOnAdd()
.HasColumnType("int"); .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CurrencyId") b.Property<int>("CurrencyId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("ProgramId") b.HasKey("ProgramId", "CurrencyId");
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CurrencyId"); b.HasIndex("CurrencyId");
b.HasIndex("ProgramId");
b.ToTable("ProgramCurrencies"); b.ToTable("ProgramCurrencies");
}); });
@ -289,9 +255,6 @@ namespace BankDatabaseImplement.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<int?>("WorkerId")
.HasColumnType("int");
b.Property<string>("WorkerName") b.Property<string>("WorkerName")
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
@ -306,8 +269,6 @@ namespace BankDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("WorkerId");
b.ToTable("Workers"); b.ToTable("Workers");
}); });
@ -325,13 +286,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ClientDeposit", b => modelBuilder.Entity("BankDatabaseImplement.Models.ClientDeposit", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Client", "Client") b.HasOne("BankDatabaseImplement.Models.Client", "Client")
.WithMany("Deposits") .WithMany("ClientDeposits")
.HasForeignKey("ClientSnils") .HasForeignKey("ClientSnils")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("BankDatabaseImplement.Models.Deposit", "Deposit") b.HasOne("BankDatabaseImplement.Models.Deposit", "Deposit")
.WithMany("Clients") .WithMany("ClientDeposits")
.HasForeignKey("DepositId") .HasForeignKey("DepositId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -344,7 +305,7 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ClientProgram", b => modelBuilder.Entity("BankDatabaseImplement.Models.ClientProgram", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Client", "Client") b.HasOne("BankDatabaseImplement.Models.Client", "Client")
.WithMany("Programs") .WithMany("ClientPrograms")
.HasForeignKey("ClientSnils") .HasForeignKey("ClientSnils")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -363,7 +324,7 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.Deposit", b => modelBuilder.Entity("BankDatabaseImplement.Models.Deposit", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Worker", "Worker") b.HasOne("BankDatabaseImplement.Models.Worker", "Worker")
.WithMany() .WithMany("Deposits")
.HasForeignKey("WorkerId") .HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -374,13 +335,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.DepositCurrency", b => modelBuilder.Entity("BankDatabaseImplement.Models.DepositCurrency", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Currency", "Currency") b.HasOne("BankDatabaseImplement.Models.Currency", "Currency")
.WithMany("Deposits") .WithMany("DepositCurrencies")
.HasForeignKey("CurrencyId") .HasForeignKey("CurrencyId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("BankDatabaseImplement.Models.Deposit", "Deposit") b.HasOne("BankDatabaseImplement.Models.Deposit", "Deposit")
.WithMany("Currencies") .WithMany("DepositCurrencies")
.HasForeignKey("DepositId") .HasForeignKey("DepositId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -393,13 +354,13 @@ namespace BankDatabaseImplement.Migrations
modelBuilder.Entity("BankDatabaseImplement.Models.ProgramCurrency", b => modelBuilder.Entity("BankDatabaseImplement.Models.ProgramCurrency", b =>
{ {
b.HasOne("BankDatabaseImplement.Models.Currency", "Currency") b.HasOne("BankDatabaseImplement.Models.Currency", "Currency")
.WithMany("Programs") .WithMany("ProgramCurrencies")
.HasForeignKey("CurrencyId") .HasForeignKey("CurrencyId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("BankDatabaseImplement.Models.Program", "Program") b.HasOne("BankDatabaseImplement.Models.Program", "Program")
.WithMany("Currencies") .WithMany("ProgramCurrencies")
.HasForeignKey("ProgramId") .HasForeignKey("ProgramId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -418,7 +379,7 @@ namespace BankDatabaseImplement.Migrations
.IsRequired(); .IsRequired();
b.HasOne("BankDatabaseImplement.Models.Worker", "Worker") b.HasOne("BankDatabaseImplement.Models.Worker", "Worker")
.WithMany() .WithMany("Refills")
.HasForeignKey("WorkerId") .HasForeignKey("WorkerId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -439,32 +400,25 @@ namespace BankDatabaseImplement.Migrations
b.Navigation("Program"); b.Navigation("Program");
}); });
modelBuilder.Entity("BankDatabaseImplement.Models.Worker", b =>
{
b.HasOne("BankDatabaseImplement.Models.Worker", null)
.WithMany("Workers")
.HasForeignKey("WorkerId");
});
modelBuilder.Entity("BankDatabaseImplement.Models.Client", b => modelBuilder.Entity("BankDatabaseImplement.Models.Client", b =>
{ {
b.Navigation("Deposits"); b.Navigation("ClientDeposits");
b.Navigation("Programs"); b.Navigation("ClientPrograms");
}); });
modelBuilder.Entity("BankDatabaseImplement.Models.Currency", b => modelBuilder.Entity("BankDatabaseImplement.Models.Currency", b =>
{ {
b.Navigation("Deposits"); b.Navigation("DepositCurrencies");
b.Navigation("Programs"); b.Navigation("ProgramCurrencies");
}); });
modelBuilder.Entity("BankDatabaseImplement.Models.Deposit", b => modelBuilder.Entity("BankDatabaseImplement.Models.Deposit", b =>
{ {
b.Navigation("Clients"); b.Navigation("ClientDeposits");
b.Navigation("Currencies"); b.Navigation("DepositCurrencies");
b.Navigation("Refills"); b.Navigation("Refills");
}); });
@ -473,14 +427,16 @@ namespace BankDatabaseImplement.Migrations
{ {
b.Navigation("Clients"); b.Navigation("Clients");
b.Navigation("Currencies"); b.Navigation("ProgramCurrencies");
b.Navigation("Terms"); b.Navigation("Terms");
}); });
modelBuilder.Entity("BankDatabaseImplement.Models.Worker", b => modelBuilder.Entity("BankDatabaseImplement.Models.Worker", b =>
{ {
b.Navigation("Workers"); b.Navigation("Deposits");
b.Navigation("Refills");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }

View File

@ -23,45 +23,39 @@ namespace BankDatabaseImplement.Models
public string PasswordHash { get; set; } = string.Empty; public string PasswordHash { get; set; } = string.Empty;
[Required] [Required]
public int WorkerId { get; set; } public int WorkerId { get; set; }
public virtual Worker? Worker { get; set; } public virtual Worker Worker { get; set; } = null!;
[ForeignKey("ClientSnils")] public virtual List<ClientProgram> ClientPrograms { get; set; } = null!;
public virtual List<ClientProgram> Programs { get; set; } = new(); public virtual List<ClientDeposit> ClientDeposits { get; set; } = null!;
private Dictionary<int, IProgramModel>? //[NotMapped]
_clientPrograms { get; set; } = null; //public Dictionary<int, IProgramModel> ClientPrograms
[ForeignKey("ClientSnils")] //{
public virtual List<ClientDeposit> Deposits { get; set; } = new(); // get
private Dictionary<int, IDepositModel>? // {
_clientDeposits { get; set; } = null; // if (_clientPrograms == null)
[NotMapped] // {
public Dictionary<int, IProgramModel> ClientPrograms // _clientPrograms = Programs.ToDictionary(
{ // x => x.ProgramId,
get // x => (x.Program as IProgramModel)
{ // );
if (_clientPrograms == null) // }
{ // return _clientPrograms;
_clientPrograms = Programs.ToDictionary( // }
x => x.ProgramId, //}
x => (x.Program as IProgramModel) //[NotMapped]
); //public Dictionary<int, IDepositModel> ClientDeposits
} //{
return _clientPrograms; // get
} // {
} // if (_clientDeposits == null)
[NotMapped] // {
public Dictionary<int, IDepositModel> ClientDeposits // _clientDeposits = Deposits.ToDictionary(
{ // x => x.DepositId,
get // x => (x.Deposit as IDepositModel)
{ // );
if (_clientDeposits == null) // }
{ // return _clientDeposits;
_clientDeposits = Deposits.ToDictionary( // }
x => x.DepositId, //}
x => (x.Deposit as IDepositModel)
);
}
return _clientDeposits;
}
}
public static Client? Create(ClientBindingModel model) public static Client? Create(ClientBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -9,12 +9,10 @@ namespace BankDatabaseImplement.Models
{ {
public class ClientDeposit public class ClientDeposit
{ {
public int Id { get; set; }
[Required]
public string ClientSnils { get; set; } = string.Empty; public string ClientSnils { get; set; } = string.Empty;
[Required] [ForeignKey("ClientSnils")]
public virtual Client Client { get; set; } = null!;
public int DepositId { get; set; } public int DepositId { get; set; }
public virtual Client Client { get; set; } = new(); public virtual Deposit Deposit { get; set; } = null!;
public virtual Deposit Deposit { get; set; } = new();
} }
} }

View File

@ -8,12 +8,10 @@ namespace BankDatabaseImplement.Models
{ {
public class ClientProgram public class ClientProgram
{ {
public int Id { get; set; }
[Required]
public string ClientSnils { get; set; } = string.Empty; public string ClientSnils { get; set; } = string.Empty;
[Required] [ForeignKey("ClientSnils")]
public virtual Client Client { get; set; } = null!;
public int ProgramId { get; set; } public int ProgramId { get; set; }
public virtual Client Client { get; set; } = new(); public virtual Program Program { get; set; } = null!;
public virtual Program Program { get; set; } = new();
} }
} }

View File

@ -15,10 +15,8 @@ namespace BankDatabaseImplement.Models
public string CurrencyName { get; set; } = string.Empty; public string CurrencyName { get; set; } = string.Empty;
[Required] [Required]
public double Course { get; set; } public double Course { get; set; }
[ForeignKey("CurrencyId")] public virtual List<DepositCurrency> DepositCurrencies { get; set; } = null!;
public virtual List<DepositCurrency> Deposits { get; set; } = new(); public virtual List<ProgramCurrency> ProgramCurrencies { get; set; } = null!;
[ForeignKey("CurrencyId")]
public virtual List<ProgramCurrency> Programs { get; set; } = new();
public static Currency? Create(CurrencyBindingModel model) public static Currency? Create(CurrencyBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -10,35 +10,12 @@ namespace BankDatabaseImplement.Models
{ {
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
public int WorkerId { get; set; }
public virtual Worker? Worker { get; set; }
[Required]
public double Sum { get; set; } public double Sum { get; set; }
[Required] [Required]
public DateOnly OpeningDate { get; set; } public DateOnly OpeningDate { get; set; }
[ForeignKey("DepositId")] public virtual List<DepositCurrency> DepositCurrencies { get; set; } = null!;
public virtual List<DepositCurrency> Currencies { get; set; } = new(); public virtual List<ClientDeposit> ClientDeposits { get; set; } = null!;
[ForeignKey("DepositId")] public virtual List<Refill> Refills { get; set; } = null!;
public virtual List<ClientDeposit> Clients { get; set; } = new();
[ForeignKey("DepositId")]
public virtual List<Refill> Refills { get; set; } = new();
private Dictionary<int, ICurrencyModel>?
_depositCurrencies { get; set; } = null;
[NotMapped]
public Dictionary<int, ICurrencyModel> DepositCurrencies
{
get
{
if (_depositCurrencies == null)
{
_depositCurrencies = Currencies.ToDictionary(
x => x.CurrencyId,
x => (x.Currency as ICurrencyModel)
);
}
return _depositCurrencies;
}
}
public static Deposit? Create(DepositBindingModel model) public static Deposit? Create(DepositBindingModel model)
{ {
if (model == null) if (model == null)
@ -46,7 +23,6 @@ namespace BankDatabaseImplement.Models
return new Deposit return new Deposit
{ {
Id = model.Id, Id = model.Id,
WorkerId = model.WorkerId,
Sum = model.Sum, Sum = model.Sum,
}; };
} }
@ -55,13 +31,11 @@ namespace BankDatabaseImplement.Models
if (model == null) if (model == null)
return; return;
Id = model.Id; Id = model.Id;
WorkerId = model.WorkerId;
Sum = model.Sum; Sum = model.Sum;
} }
public DepositViewModel GetViewModel => new() public DepositViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
WorkerId = WorkerId,
Sum = Sum, Sum = Sum,
}; };
} }

View File

@ -8,12 +8,9 @@ namespace BankDatabaseImplement.Models
{ {
public class DepositCurrency public class DepositCurrency
{ {
public int Id { get; set; }
[Required]
public int DepositId { get; set; } public int DepositId { get; set; }
[Required] public virtual Deposit Deposit { get; set; } = null!;
public int CurrencyId { get; set; } public int CurrencyId { get; set; }
public virtual Deposit Deposit { get; set; } = new(); public virtual Currency Currency { get; set; } = null!;
public virtual Currency Currency { get; set; } = new();
} }
} }

View File

@ -13,30 +13,9 @@ namespace BankDatabaseImplement.Models
public string ProgramName { get; set; } = string.Empty; public string ProgramName { get; set; } = string.Empty;
[Required] [Required]
public double InterestRate { get; set; } public double InterestRate { get; set; }
[ForeignKey("ProgramId")] public virtual List<ProgramCurrency> ProgramCurrencies { get; set; } = null!;
public virtual List<ProgramCurrency> Currencies { get; set; } = new(); public virtual List<ClientProgram> Clients { get; set; } = null!;
[ForeignKey("ProgramId")] public virtual List<Term> Terms { get; set; } = null!;
public virtual List<ClientProgram> Clients { get; set; } = new();
[ForeignKey("ProgramId")]
public virtual List<Term> Terms { get; set; } = new();
private Dictionary<int, ICurrencyModel>?
_programCurrencies
{ get; set; } = null;
[NotMapped]
public Dictionary<int, ICurrencyModel> ProgramCurrencies
{
get
{
if (_programCurrencies == null)
{
_programCurrencies = Currencies.ToDictionary(
x => x.CurrencyId,
x => (x.Currency as ICurrencyModel)
);
}
return _programCurrencies;
}
}
public static Program? Create(ProgramBindingModel model) public static Program? Create(ProgramBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -8,12 +8,9 @@ namespace BankDatabaseImplement.Models
{ {
public class ProgramCurrency public class ProgramCurrency
{ {
public int Id { get; set; }
[Required]
public int ProgramId { get; set; } public int ProgramId { get; set; }
[Required] public virtual Program Program { get; set; } = null!;
public int CurrencyId { get; set; } public int CurrencyId { get; set; }
public virtual Program Program { get; set; } = new(); public virtual Currency Currency { get; set; } = null!;
public virtual Currency Currency { get; set; } = new();
} }
} }

View File

@ -11,10 +11,7 @@ namespace BankDatabaseImplement.Models
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
public int DepositId { get; set; } public int DepositId { get; set; }
public virtual Deposit? Deposit { get; set; } public virtual Deposit Deposit { get; set; } = null!;
[Required]
public int WorkerId { get; set; }
public virtual Worker? Worker { get; set; }
[Required] [Required]
public double Sum { get; set; } public double Sum { get; set; }
[Required] [Required]
@ -27,7 +24,6 @@ namespace BankDatabaseImplement.Models
{ {
Id = model.Id, Id = model.Id,
DepositId = model.DepositId, DepositId = model.DepositId,
WorkerId = model.WorkerId,
Sum = model.Sum, Sum = model.Sum,
RefillDate = model.RefillDate, RefillDate = model.RefillDate,
}; };
@ -38,7 +34,6 @@ namespace BankDatabaseImplement.Models
return; return;
Id = model.Id; Id = model.Id;
DepositId = model.DepositId; DepositId = model.DepositId;
WorkerId = model.WorkerId;
Sum = model.Sum; Sum = model.Sum;
RefillDate = model.RefillDate; RefillDate = model.RefillDate;
} }
@ -46,7 +41,6 @@ namespace BankDatabaseImplement.Models
{ {
Id = Id, Id = Id,
DepositId = DepositId, DepositId = DepositId,
WorkerId = WorkerId,
Sum = Sum, Sum = Sum,
RefillDate = RefillDate, RefillDate = RefillDate,
}; };

View File

@ -10,10 +10,10 @@ namespace BankDatabaseImplement.Models
{ {
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
public int Duration { get; set; }
[Required]
public int ProgramId { get; set; } public int ProgramId { get; set; }
public virtual Program? Program { get; set; } public virtual Program Program { get; set; } = null!;
[Required]
public int Duration { get; set; }
public static Term? Create(TermBindingModel model) public static Term? Create(TermBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -21,8 +21,8 @@ namespace BankDatabaseImplement.Models
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[Required] [Required]
public string PasswordHash { get; set; } = string.Empty; public string PasswordHash { get; set; } = string.Empty;
[ForeignKey("WorkerId")] public List<Deposit> Deposits { get; set; } = null!;
public virtual List<Worker> Workers { get; set; } = new(); public List<Refill> Refills { get; set; } = null!;
public static Worker? Create(WorkerBindingModel model) public static Worker? Create(WorkerBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -1,30 +1,20 @@
{ {
"$schema": "http://json.schemastore.org/launchsettings.json", "$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": { "iisSettings": {
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:64404", "applicationUrl": "http://localhost:27552",
"sslPort": 44307 "sslPort": 44383
} }
}, },
"profiles": { "profiles": {
"http": { "BankRestApi": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "swagger", "launchUrl": "swagger",
"applicationUrl": "http://localhost:5142", "applicationUrl": "https://localhost:7177;http://localhost:5116",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7061;http://localhost:5142",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

View File

@ -1,5 +1,5 @@
using BankWorkerApp.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using BankWorkerApp.Models;
using System.Diagnostics; using System.Diagnostics;
namespace BankWorkerApp.Controllers namespace BankWorkerApp.Controllers

View File

@ -10,6 +10,7 @@ namespace BankWorkerApp
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())

View File

@ -8,7 +8,7 @@
} }
}, },
"profiles": { "profiles": {
"BankWorkerApp": { "BankManagersClientApp": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
@ -26,3 +26,4 @@
} }
} }
} }

View File

@ -1,7 +1,6 @@
@{ @{
ViewData["Title"] = "Home Page"; ViewData["Title"] = "Home Page";
} }
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Welcome</h1> <h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> <p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>

View File

@ -19,6 +19,6 @@ html {
body { body {
overflow-x: hidden; overflow-x: hidden;
background-color: #B2309D; background-color: #FFA500;
min-height: 100vh; min-height: 100vh;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 15 KiB