diff --git a/RentalBusiness/Enums/CarStatus.cs b/RentalBusiness/Enums/CarStatus.cs
new file mode 100644
index 0000000..0c7c5d0
--- /dev/null
+++ b/RentalBusiness/Enums/CarStatus.cs
@@ -0,0 +1,8 @@
+namespace RentalBusiness.Enums
+{
+ public enum CarStatus
+ {
+ Available = 0,
+ IsTaken = 1
+ }
+}
diff --git a/RentalBusiness/Enums/ContractStatus.cs b/RentalBusiness/Enums/ContractStatus.cs
new file mode 100644
index 0000000..f238901
--- /dev/null
+++ b/RentalBusiness/Enums/ContractStatus.cs
@@ -0,0 +1,9 @@
+namespace RentalBusiness.Enums
+{
+ public enum ContractStatus
+ {
+ InProcess = 0,
+ Finished = 1,
+ Expired = 2
+ }
+}
diff --git a/RentalBusiness/Migrations/20230402145704_EnumsCreation.Designer.cs b/RentalBusiness/Migrations/20230402145704_EnumsCreation.Designer.cs
new file mode 100644
index 0000000..e4cf476
--- /dev/null
+++ b/RentalBusiness/Migrations/20230402145704_EnumsCreation.Designer.cs
@@ -0,0 +1,316 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using RentalBusiness.Enums;
+using RentalBusiness.Models;
+
+#nullable disable
+
+namespace RentalBusiness.Migrations
+{
+ [DbContext(typeof(RentalbusinessContext))]
+ [Migration("20230402145704_EnumsCreation")]
+ partial class EnumsCreation
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.4")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "car_status", new[] { "available", "is_taken" });
+ NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "contract_status", new[] { "in_process", "finished", "expired" });
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("RentalBusiness.Models.Brand", b =>
+ {
+ b.Property("BrandId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("brand_id")
+ .HasComment("Contains serial variable to identify each car brand.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("BrandId"));
+
+ b.Property("BrandName")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("brand_name")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains brand name of car.");
+
+ b.Property("BrandRatio")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("brand_ratio")
+ .HasDefaultValueSql("1")
+ .HasComment("Contains ratio to calculate renting price.");
+
+ b.HasKey("BrandId")
+ .HasName("brand_pkey");
+
+ b.ToTable("brand", null, t =>
+ {
+ t.HasComment("Contains info about existing brand names and their ratio for future renting price.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Contract", b =>
+ {
+ b.Property("ContractId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("contract_id")
+ .HasComment("Contains serial variable to identify each contract.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ContractId"));
+
+ b.Property("CarId")
+ .HasColumnType("integer")
+ .HasColumnName("car_id")
+ .HasComment("Contains key which depicts a specific car from foreign table.");
+
+ b.Property("CustomerId")
+ .HasColumnType("integer")
+ .HasColumnName("customer_id")
+ .HasComment("Contains key which depicts a specific customer from foreign table.");
+
+ b.Property("Price")
+ .HasPrecision(10)
+ .HasColumnType("numeric(10)")
+ .HasColumnName("price")
+ .HasComment("Contains a total cost of a contract from brand and model ration multiplying the length of rental date.");
+
+ b.Property("RentalDate")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp without time zone")
+ .HasColumnName("rental_date")
+ .HasDefaultValueSql("'1111-01-01 00:00:00'::timestamp without time zone")
+ .HasComment("Contains info about start rental date.");
+
+ b.Property("ReturnDate")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp without time zone")
+ .HasColumnName("return_date")
+ .HasDefaultValueSql("'1111-01-01 00:00:00'::timestamp without time zone")
+ .HasComment("Contains info about ending rental date.");
+
+ b.Property("Status")
+ .HasColumnType("contract_status");
+
+ b.HasKey("ContractId")
+ .HasName("contract_pkey");
+
+ b.HasIndex("CarId");
+
+ b.HasIndex("CustomerId");
+
+ b.ToTable("contract", null, t =>
+ {
+ t.HasComment("Contains info about contracts which have ever been made.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Customer", b =>
+ {
+ b.Property("CustomerId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("customer_id")
+ .HasComment("Contains serial variable to identify each customer.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CustomerId"));
+
+ b.Property("FirstName")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("first_name")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains first name of a customer.");
+
+ b.Property("IdCard")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("id_card")
+ .HasDefaultValueSql("0")
+ .HasComment("Contains id card digits.");
+
+ b.Property("LastName")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("last_name")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains last name of a customer.");
+
+ b.Property("MiddleName")
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("middle_name")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains(if exists) middle name of a customer.");
+
+ b.HasKey("CustomerId")
+ .HasName("customer_pkey");
+
+ b.ToTable("customer", null, t =>
+ {
+ t.HasComment("Contains info about customer who have ever rented cars.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Model", b =>
+ {
+ b.Property("ModelId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("model_id")
+ .HasComment("Contains serial variable to identify each model specification.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ModelId"));
+
+ b.Property("ModelRatio")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("model_ratio")
+ .HasDefaultValueSql("1")
+ .HasComment("Contains ratio of model specification to calculate price of renting.");
+
+ b.Property("ModelSpec")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("model_spec")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains name of model specification.");
+
+ b.HasKey("ModelId")
+ .HasName("model_pkey");
+
+ b.ToTable("model", null, t =>
+ {
+ t.HasComment("Contains info about existing model specifications and ration for future calculation of renting price.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Storage", b =>
+ {
+ b.Property("CarId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("car_id")
+ .HasComment("Contains serial variable to identify each car.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CarId"));
+
+ b.Property("BrandId")
+ .HasColumnType("integer")
+ .HasColumnName("brand_id")
+ .HasComment("Contains key from brand table which depicts brand.");
+
+ b.Property("CarRatioPerHour")
+ .HasColumnType("integer")
+ .HasColumnName("car_ratio_per_hour")
+ .HasComment("Contains variable which consists of ratio from model and brand columns in foreign tables.");
+
+ b.Property("ModelId")
+ .HasColumnType("integer")
+ .HasColumnName("model_id")
+ .HasComment("Contains key from model table which depicts model.");
+
+ b.Property("Status")
+ .HasColumnType("car_status");
+
+ b.HasKey("CarId")
+ .HasName("storage_pkey");
+
+ b.HasIndex("BrandId");
+
+ b.HasIndex("ModelId");
+
+ b.ToTable("storage", null, t =>
+ {
+ t.HasComment("Contains info about available cars for renting.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Contract", b =>
+ {
+ b.HasOne("RentalBusiness.Models.Storage", "Car")
+ .WithMany("Contracts")
+ .HasForeignKey("CarId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("contract_storage_id_fkey");
+
+ b.HasOne("RentalBusiness.Models.Customer", "Customer")
+ .WithMany("Contracts")
+ .HasForeignKey("CustomerId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("contract_customer_id_fkey");
+
+ b.Navigation("Car");
+
+ b.Navigation("Customer");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Storage", b =>
+ {
+ b.HasOne("RentalBusiness.Models.Brand", "Brand")
+ .WithMany("Storages")
+ .HasForeignKey("BrandId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("storage_brand_id_fkey");
+
+ b.HasOne("RentalBusiness.Models.Model", "Model")
+ .WithMany("Storages")
+ .HasForeignKey("ModelId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("storage_model_id_fkey");
+
+ b.Navigation("Brand");
+
+ b.Navigation("Model");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Brand", b =>
+ {
+ b.Navigation("Storages");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Customer", b =>
+ {
+ b.Navigation("Contracts");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Model", b =>
+ {
+ b.Navigation("Storages");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Storage", b =>
+ {
+ b.Navigation("Contracts");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/RentalBusiness/Migrations/20230402145704_EnumsCreation.cs b/RentalBusiness/Migrations/20230402145704_EnumsCreation.cs
new file mode 100644
index 0000000..60ab718
--- /dev/null
+++ b/RentalBusiness/Migrations/20230402145704_EnumsCreation.cs
@@ -0,0 +1,167 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using RentalBusiness.Enums;
+
+#nullable disable
+
+namespace RentalBusiness.Migrations
+{
+ ///
+ public partial class EnumsCreation : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AlterDatabase()
+ .Annotation("Npgsql:Enum:car_status", "available,is_taken")
+ .Annotation("Npgsql:Enum:contract_status", "in_process,finished,expired");
+
+ migrationBuilder.CreateTable(
+ name: "brand",
+ columns: table => new
+ {
+ brand_id = table.Column(type: "integer", nullable: false, comment: "Contains serial variable to identify each car brand.")
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ brand_name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "'unknown'::character varying", comment: "Contains brand name of car."),
+ brand_ratio = table.Column(type: "integer", nullable: false, defaultValueSql: "1", comment: "Contains ratio to calculate renting price.")
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("brand_pkey", x => x.brand_id);
+ },
+ comment: "Contains info about existing brand names and their ratio for future renting price.");
+
+ migrationBuilder.CreateTable(
+ name: "customer",
+ columns: table => new
+ {
+ customer_id = table.Column(type: "integer", nullable: false, comment: "Contains serial variable to identify each customer.")
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ last_name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "'unknown'::character varying", comment: "Contains last name of a customer."),
+ first_name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "'unknown'::character varying", comment: "Contains first name of a customer."),
+ middle_name = table.Column(type: "character varying(255)", maxLength: 255, nullable: true, defaultValueSql: "'unknown'::character varying", comment: "Contains(if exists) middle name of a customer."),
+ id_card = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "0", comment: "Contains id card digits.")
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("customer_pkey", x => x.customer_id);
+ },
+ comment: "Contains info about customer who have ever rented cars.");
+
+ migrationBuilder.CreateTable(
+ name: "model",
+ columns: table => new
+ {
+ model_id = table.Column(type: "integer", nullable: false, comment: "Contains serial variable to identify each model specification.")
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ model_spec = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "'unknown'::character varying", comment: "Contains name of model specification."),
+ model_ratio = table.Column(type: "integer", nullable: false, defaultValueSql: "1", comment: "Contains ratio of model specification to calculate price of renting.")
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("model_pkey", x => x.model_id);
+ },
+ comment: "Contains info about existing model specifications and ration for future calculation of renting price.");
+
+ migrationBuilder.CreateTable(
+ name: "storage",
+ columns: table => new
+ {
+ car_id = table.Column(type: "integer", nullable: false, comment: "Contains serial variable to identify each car.")
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ brand_id = table.Column(type: "integer", nullable: false, comment: "Contains key from brand table which depicts brand."),
+ model_id = table.Column(type: "integer", nullable: false, comment: "Contains key from model table which depicts model."),
+ car_ratio_per_hour = table.Column(type: "integer", nullable: false, comment: "Contains variable which consists of ratio from model and brand columns in foreign tables."),
+ car_status = table.Column(type: "car_status", nullable: false, comment: "Contains the current state of car, whether it's available for rent or not.")
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("storage_pkey", x => x.car_id);
+ table.ForeignKey(
+ name: "storage_brand_id_fkey",
+ column: x => x.brand_id,
+ principalTable: "brand",
+ principalColumn: "brand_id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "storage_model_id_fkey",
+ column: x => x.model_id,
+ principalTable: "model",
+ principalColumn: "model_id",
+ onDelete: ReferentialAction.Cascade);
+ },
+ comment: "Contains info about available cars for renting.");
+
+ migrationBuilder.CreateTable(
+ name: "contract",
+ columns: table => new
+ {
+ contract_id = table.Column(type: "integer", nullable: false, comment: "Contains serial variable to identify each contract.")
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ car_id = table.Column(type: "integer", nullable: false, comment: "Contains key which depicts a specific car from foreign table."),
+ customer_id = table.Column(type: "integer", nullable: false, comment: "Contains key which depicts a specific customer from foreign table."),
+ rental_date = table.Column(type: "timestamp without time zone", nullable: false, defaultValueSql: "'1111-01-01 00:00:00'::timestamp without time zone", comment: "Contains info about start rental date."),
+ return_date = table.Column(type: "timestamp without time zone", nullable: false, defaultValueSql: "'1111-01-01 00:00:00'::timestamp without time zone", comment: "Contains info about ending rental date."),
+ price = table.Column(type: "numeric(10)", precision: 10, nullable: false, comment: "Contains a total cost of a contract from brand and model ration multiplying the length of rental date."),
+ contract_status = table.Column(type: "contract_status", nullable: false, comment: "Contains the current state of contract.")
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("contract_pkey", x => x.contract_id);
+ table.ForeignKey(
+ name: "contract_customer_id_fkey",
+ column: x => x.customer_id,
+ principalTable: "customer",
+ principalColumn: "customer_id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "contract_storage_id_fkey",
+ column: x => x.car_id,
+ principalTable: "storage",
+ principalColumn: "car_id",
+ onDelete: ReferentialAction.Cascade);
+ },
+ comment: "Contains info about contracts which have ever been made.");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_contract_car_id",
+ table: "contract",
+ column: "car_id");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_contract_customer_id",
+ table: "contract",
+ column: "customer_id");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_storage_brand_id",
+ table: "storage",
+ column: "brand_id");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_storage_model_id",
+ table: "storage",
+ column: "model_id");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "contract");
+
+ migrationBuilder.DropTable(
+ name: "customer");
+
+ migrationBuilder.DropTable(
+ name: "storage");
+
+ migrationBuilder.DropTable(
+ name: "brand");
+
+ migrationBuilder.DropTable(
+ name: "model");
+ }
+ }
+}
diff --git a/RentalBusiness/Migrations/RentalbusinessContextModelSnapshot.cs b/RentalBusiness/Migrations/RentalbusinessContextModelSnapshot.cs
new file mode 100644
index 0000000..58d944d
--- /dev/null
+++ b/RentalBusiness/Migrations/RentalbusinessContextModelSnapshot.cs
@@ -0,0 +1,313 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using RentalBusiness.Enums;
+using RentalBusiness.Models;
+
+#nullable disable
+
+namespace RentalBusiness.Migrations
+{
+ [DbContext(typeof(RentalbusinessContext))]
+ partial class RentalbusinessContextModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.4")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "car_status", new[] { "available", "is_taken" });
+ NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "contract_status", new[] { "in_process", "finished", "expired" });
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("RentalBusiness.Models.Brand", b =>
+ {
+ b.Property("BrandId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("brand_id")
+ .HasComment("Contains serial variable to identify each car brand.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("BrandId"));
+
+ b.Property("BrandName")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("brand_name")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains brand name of car.");
+
+ b.Property("BrandRatio")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("brand_ratio")
+ .HasDefaultValueSql("1")
+ .HasComment("Contains ratio to calculate renting price.");
+
+ b.HasKey("BrandId")
+ .HasName("brand_pkey");
+
+ b.ToTable("brand", null, t =>
+ {
+ t.HasComment("Contains info about existing brand names and their ratio for future renting price.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Contract", b =>
+ {
+ b.Property("ContractId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("contract_id")
+ .HasComment("Contains serial variable to identify each contract.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ContractId"));
+
+ b.Property("CarId")
+ .HasColumnType("integer")
+ .HasColumnName("car_id")
+ .HasComment("Contains key which depicts a specific car from foreign table.");
+
+ b.Property("CustomerId")
+ .HasColumnType("integer")
+ .HasColumnName("customer_id")
+ .HasComment("Contains key which depicts a specific customer from foreign table.");
+
+ b.Property("Price")
+ .HasPrecision(10)
+ .HasColumnType("numeric(10)")
+ .HasColumnName("price")
+ .HasComment("Contains a total cost of a contract from brand and model ration multiplying the length of rental date.");
+
+ b.Property("RentalDate")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp without time zone")
+ .HasColumnName("rental_date")
+ .HasDefaultValueSql("'1111-01-01 00:00:00'::timestamp without time zone")
+ .HasComment("Contains info about start rental date.");
+
+ b.Property("ReturnDate")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp without time zone")
+ .HasColumnName("return_date")
+ .HasDefaultValueSql("'1111-01-01 00:00:00'::timestamp without time zone")
+ .HasComment("Contains info about ending rental date.");
+
+ b.Property("Status")
+ .HasColumnType("contract_status");
+
+ b.HasKey("ContractId")
+ .HasName("contract_pkey");
+
+ b.HasIndex("CarId");
+
+ b.HasIndex("CustomerId");
+
+ b.ToTable("contract", null, t =>
+ {
+ t.HasComment("Contains info about contracts which have ever been made.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Customer", b =>
+ {
+ b.Property("CustomerId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("customer_id")
+ .HasComment("Contains serial variable to identify each customer.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CustomerId"));
+
+ b.Property("FirstName")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("first_name")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains first name of a customer.");
+
+ b.Property("IdCard")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("id_card")
+ .HasDefaultValueSql("0")
+ .HasComment("Contains id card digits.");
+
+ b.Property("LastName")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("last_name")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains last name of a customer.");
+
+ b.Property("MiddleName")
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("middle_name")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains(if exists) middle name of a customer.");
+
+ b.HasKey("CustomerId")
+ .HasName("customer_pkey");
+
+ b.ToTable("customer", null, t =>
+ {
+ t.HasComment("Contains info about customer who have ever rented cars.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Model", b =>
+ {
+ b.Property("ModelId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("model_id")
+ .HasComment("Contains serial variable to identify each model specification.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ModelId"));
+
+ b.Property("ModelRatio")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("model_ratio")
+ .HasDefaultValueSql("1")
+ .HasComment("Contains ratio of model specification to calculate price of renting.");
+
+ b.Property("ModelSpec")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)")
+ .HasColumnName("model_spec")
+ .HasDefaultValueSql("'unknown'::character varying")
+ .HasComment("Contains name of model specification.");
+
+ b.HasKey("ModelId")
+ .HasName("model_pkey");
+
+ b.ToTable("model", null, t =>
+ {
+ t.HasComment("Contains info about existing model specifications and ration for future calculation of renting price.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Storage", b =>
+ {
+ b.Property("CarId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .HasColumnName("car_id")
+ .HasComment("Contains serial variable to identify each car.");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("CarId"));
+
+ b.Property("BrandId")
+ .HasColumnType("integer")
+ .HasColumnName("brand_id")
+ .HasComment("Contains key from brand table which depicts brand.");
+
+ b.Property("CarRatioPerHour")
+ .HasColumnType("integer")
+ .HasColumnName("car_ratio_per_hour")
+ .HasComment("Contains variable which consists of ratio from model and brand columns in foreign tables.");
+
+ b.Property("ModelId")
+ .HasColumnType("integer")
+ .HasColumnName("model_id")
+ .HasComment("Contains key from model table which depicts model.");
+
+ b.Property("Status")
+ .HasColumnType("car_status");
+
+ b.HasKey("CarId")
+ .HasName("storage_pkey");
+
+ b.HasIndex("BrandId");
+
+ b.HasIndex("ModelId");
+
+ b.ToTable("storage", null, t =>
+ {
+ t.HasComment("Contains info about available cars for renting.");
+ });
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Contract", b =>
+ {
+ b.HasOne("RentalBusiness.Models.Storage", "Car")
+ .WithMany("Contracts")
+ .HasForeignKey("CarId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("contract_storage_id_fkey");
+
+ b.HasOne("RentalBusiness.Models.Customer", "Customer")
+ .WithMany("Contracts")
+ .HasForeignKey("CustomerId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("contract_customer_id_fkey");
+
+ b.Navigation("Car");
+
+ b.Navigation("Customer");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Storage", b =>
+ {
+ b.HasOne("RentalBusiness.Models.Brand", "Brand")
+ .WithMany("Storages")
+ .HasForeignKey("BrandId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("storage_brand_id_fkey");
+
+ b.HasOne("RentalBusiness.Models.Model", "Model")
+ .WithMany("Storages")
+ .HasForeignKey("ModelId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("storage_model_id_fkey");
+
+ b.Navigation("Brand");
+
+ b.Navigation("Model");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Brand", b =>
+ {
+ b.Navigation("Storages");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Customer", b =>
+ {
+ b.Navigation("Contracts");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Model", b =>
+ {
+ b.Navigation("Storages");
+ });
+
+ modelBuilder.Entity("RentalBusiness.Models.Storage", b =>
+ {
+ b.Navigation("Contracts");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/RentalBusiness/Models/Contract.cs b/RentalBusiness/Models/Contract.cs
index 1c88c21..99d91ae 100644
--- a/RentalBusiness/Models/Contract.cs
+++ b/RentalBusiness/Models/Contract.cs
@@ -1,4 +1,5 @@
-using System;
+using RentalBusiness.Enums;
+using System;
using System.Collections.Generic;
namespace RentalBusiness.Models;
@@ -37,6 +38,10 @@ public partial class Contract
/// Contains a total cost of a contract from brand and model ration multiplying the length of rental date.
///
public decimal Price { get; set; }
+ ///
+ /// Contains a current state of contract.
+ ///
+ public ContractStatus Status { get; set; }
public virtual Storage Car { get; set; } = null!;
diff --git a/RentalBusiness/Models/RentalbusinessContext.cs b/RentalBusiness/Models/RentalbusinessContext.cs
index 890100c..292edc3 100644
--- a/RentalBusiness/Models/RentalbusinessContext.cs
+++ b/RentalBusiness/Models/RentalbusinessContext.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
+using Npgsql;
+using RentalBusiness.Enums;
namespace RentalBusiness.Models;
@@ -25,15 +27,18 @@ public partial class RentalbusinessContext : DbContext
public virtual DbSet Storages { get; set; }
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
-#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
- => optionsBuilder.UseNpgsql("Server=192.168.56.101;Database=rentalbusiness;Username=nikitadb;Password=labwork2");
+ static RentalbusinessContext()
+ {
+ NpgsqlConnection.GlobalTypeMapper.MapEnum();
+ NpgsqlConnection.GlobalTypeMapper.MapEnum();
+ }
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=local;Username=postgres;Password=postgres");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
- .HasPostgresEnum("car_status", new[] { "Available", "IsTaken" })
- .HasPostgresEnum("contract_status", new[] { "In process", "Finished", "Expired" });
+ .HasPostgresEnum()
+ .HasPostgresEnum();
modelBuilder.Entity(entity =>
{
diff --git a/RentalBusiness/Models/Storage.cs b/RentalBusiness/Models/Storage.cs
index 6e187d7..002263a 100644
--- a/RentalBusiness/Models/Storage.cs
+++ b/RentalBusiness/Models/Storage.cs
@@ -1,4 +1,5 @@
-using System;
+using RentalBusiness.Enums;
+using System;
using System.Collections.Generic;
namespace RentalBusiness.Models;
@@ -27,6 +28,10 @@ public partial class Storage
/// Contains variable which consists of ratio from model and brand columns in foreign tables.
///
public int CarRatioPerHour { get; set; }
+ ///
+ /// Contains a current state of car.
+ ///
+ public CarStatus Status { get; set; }
public virtual Brand Brand { get; set; } = null!;
diff --git a/RentalBusiness/Program.cs b/RentalBusiness/Program.cs
index 3155fc3..7f2e1be 100644
--- a/RentalBusiness/Program.cs
+++ b/RentalBusiness/Program.cs
@@ -1,7 +1,14 @@
+using Microsoft.EntityFrameworkCore;
+using Npgsql;
+using RentalBusiness.Enums;
+using RentalBusiness.Models;
+
var builder = WebApplication.CreateBuilder(args);
+
// Add services to the container.
builder.Services.AddControllersWithViews();
+builder.Services.AddDbContext(options => options.UseNpgsql(builder.Configuration.GetConnectionString("ASPDB")));
var app = builder.Build();
diff --git a/RentalBusiness/appsettings.json b/RentalBusiness/appsettings.json
index 10f68b8..d9a0360 100644
--- a/RentalBusiness/appsettings.json
+++ b/RentalBusiness/appsettings.json
@@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
- "AllowedHosts": "*"
+ "AllowedHosts": "*",
+ "ConnectionStrings": {
+ "ASPDB": "Host=localhost;Database=local;Username=postgres;Password="
+ }
}