Enums were created and migrations were applied to new database.
This commit is contained in:
parent
f8a3f12757
commit
0b24219be5
8
RentalBusiness/Enums/CarStatus.cs
Normal file
8
RentalBusiness/Enums/CarStatus.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace RentalBusiness.Enums
|
||||
{
|
||||
public enum CarStatus
|
||||
{
|
||||
Available = 0,
|
||||
IsTaken = 1
|
||||
}
|
||||
}
|
9
RentalBusiness/Enums/ContractStatus.cs
Normal file
9
RentalBusiness/Enums/ContractStatus.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace RentalBusiness.Enums
|
||||
{
|
||||
public enum ContractStatus
|
||||
{
|
||||
InProcess = 0,
|
||||
Finished = 1,
|
||||
Expired = 2
|
||||
}
|
||||
}
|
316
RentalBusiness/Migrations/20230402145704_EnumsCreation.Designer.cs
generated
Normal file
316
RentalBusiness/Migrations/20230402145704_EnumsCreation.Designer.cs
generated
Normal file
@ -0,0 +1,316 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("BrandId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("brand_id")
|
||||
.HasComment("Contains serial variable to identify each car brand.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("BrandId"));
|
||||
|
||||
b.Property<string>("BrandName")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("brand_name")
|
||||
.HasDefaultValueSql("'unknown'::character varying")
|
||||
.HasComment("Contains brand name of car.");
|
||||
|
||||
b.Property<int>("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<int>("ContractId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("contract_id")
|
||||
.HasComment("Contains serial variable to identify each contract.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ContractId"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_id")
|
||||
.HasComment("Contains key which depicts a specific car from foreign table.");
|
||||
|
||||
b.Property<int>("CustomerId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("customer_id")
|
||||
.HasComment("Contains key which depicts a specific customer from foreign table.");
|
||||
|
||||
b.Property<decimal>("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<DateTime>("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<DateTime>("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<ContractStatus>("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<int>("CustomerId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("customer_id")
|
||||
.HasComment("Contains serial variable to identify each customer.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("CustomerId"));
|
||||
|
||||
b.Property<string>("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<string>("IdCard")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("id_card")
|
||||
.HasDefaultValueSql("0")
|
||||
.HasComment("Contains id card digits.");
|
||||
|
||||
b.Property<string>("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<string>("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<int>("ModelId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_id")
|
||||
.HasComment("Contains serial variable to identify each model specification.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ModelId"));
|
||||
|
||||
b.Property<int>("ModelRatio")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_ratio")
|
||||
.HasDefaultValueSql("1")
|
||||
.HasComment("Contains ratio of model specification to calculate price of renting.");
|
||||
|
||||
b.Property<string>("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<int>("CarId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_id")
|
||||
.HasComment("Contains serial variable to identify each car.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("CarId"));
|
||||
|
||||
b.Property<int>("BrandId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("brand_id")
|
||||
.HasComment("Contains key from brand table which depicts brand.");
|
||||
|
||||
b.Property<int>("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<int>("ModelId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_id")
|
||||
.HasComment("Contains key from model table which depicts model.");
|
||||
|
||||
b.Property<CarStatus>("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
|
||||
}
|
||||
}
|
||||
}
|
167
RentalBusiness/Migrations/20230402145704_EnumsCreation.cs
Normal file
167
RentalBusiness/Migrations/20230402145704_EnumsCreation.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using RentalBusiness.Enums;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RentalBusiness.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class EnumsCreation : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>(type: "integer", nullable: false, comment: "Contains serial variable to identify each car brand.")
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
brand_name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "'unknown'::character varying", comment: "Contains brand name of car."),
|
||||
brand_ratio = table.Column<int>(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<int>(type: "integer", nullable: false, comment: "Contains serial variable to identify each customer.")
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
last_name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "'unknown'::character varying", comment: "Contains last name of a customer."),
|
||||
first_name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "'unknown'::character varying", comment: "Contains first name of a customer."),
|
||||
middle_name = table.Column<string>(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<string>(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<int>(type: "integer", nullable: false, comment: "Contains serial variable to identify each model specification.")
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
model_spec = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false, defaultValueSql: "'unknown'::character varying", comment: "Contains name of model specification."),
|
||||
model_ratio = table.Column<int>(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<int>(type: "integer", nullable: false, comment: "Contains serial variable to identify each car.")
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
brand_id = table.Column<int>(type: "integer", nullable: false, comment: "Contains key from brand table which depicts brand."),
|
||||
model_id = table.Column<int>(type: "integer", nullable: false, comment: "Contains key from model table which depicts model."),
|
||||
car_ratio_per_hour = table.Column<int>(type: "integer", nullable: false, comment: "Contains variable which consists of ratio from model and brand columns in foreign tables."),
|
||||
car_status = table.Column<CarStatus>(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<int>(type: "integer", nullable: false, comment: "Contains serial variable to identify each contract.")
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
car_id = table.Column<int>(type: "integer", nullable: false, comment: "Contains key which depicts a specific car from foreign table."),
|
||||
customer_id = table.Column<int>(type: "integer", nullable: false, comment: "Contains key which depicts a specific customer from foreign table."),
|
||||
rental_date = table.Column<DateTime>(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<DateTime>(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<decimal>(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<ContractStatus>(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");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
313
RentalBusiness/Migrations/RentalbusinessContextModelSnapshot.cs
Normal file
313
RentalBusiness/Migrations/RentalbusinessContextModelSnapshot.cs
Normal file
@ -0,0 +1,313 @@
|
||||
// <auto-generated />
|
||||
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<int>("BrandId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("brand_id")
|
||||
.HasComment("Contains serial variable to identify each car brand.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("BrandId"));
|
||||
|
||||
b.Property<string>("BrandName")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("brand_name")
|
||||
.HasDefaultValueSql("'unknown'::character varying")
|
||||
.HasComment("Contains brand name of car.");
|
||||
|
||||
b.Property<int>("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<int>("ContractId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("contract_id")
|
||||
.HasComment("Contains serial variable to identify each contract.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ContractId"));
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_id")
|
||||
.HasComment("Contains key which depicts a specific car from foreign table.");
|
||||
|
||||
b.Property<int>("CustomerId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("customer_id")
|
||||
.HasComment("Contains key which depicts a specific customer from foreign table.");
|
||||
|
||||
b.Property<decimal>("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<DateTime>("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<DateTime>("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<ContractStatus>("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<int>("CustomerId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("customer_id")
|
||||
.HasComment("Contains serial variable to identify each customer.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("CustomerId"));
|
||||
|
||||
b.Property<string>("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<string>("IdCard")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("id_card")
|
||||
.HasDefaultValueSql("0")
|
||||
.HasComment("Contains id card digits.");
|
||||
|
||||
b.Property<string>("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<string>("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<int>("ModelId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_id")
|
||||
.HasComment("Contains serial variable to identify each model specification.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("ModelId"));
|
||||
|
||||
b.Property<int>("ModelRatio")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_ratio")
|
||||
.HasDefaultValueSql("1")
|
||||
.HasComment("Contains ratio of model specification to calculate price of renting.");
|
||||
|
||||
b.Property<string>("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<int>("CarId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_id")
|
||||
.HasComment("Contains serial variable to identify each car.");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("CarId"));
|
||||
|
||||
b.Property<int>("BrandId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("brand_id")
|
||||
.HasComment("Contains key from brand table which depicts brand.");
|
||||
|
||||
b.Property<int>("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<int>("ModelId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_id")
|
||||
.HasComment("Contains key from model table which depicts model.");
|
||||
|
||||
b.Property<CarStatus>("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
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
/// </summary>
|
||||
public decimal Price { get; set; }
|
||||
/// <summary>
|
||||
/// Contains a current state of contract.
|
||||
/// </summary>
|
||||
public ContractStatus Status { get; set; }
|
||||
|
||||
public virtual Storage Car { get; set; } = null!;
|
||||
|
||||
|
@ -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<Storage> 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<CarStatus>();
|
||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<ContractStatus>();
|
||||
}
|
||||
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<CarStatus>()
|
||||
.HasPostgresEnum<ContractStatus>();
|
||||
|
||||
modelBuilder.Entity<Brand>(entity =>
|
||||
{
|
||||
|
@ -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.
|
||||
/// </summary>
|
||||
public int CarRatioPerHour { get; set; }
|
||||
/// <summary>
|
||||
/// Contains a current state of car.
|
||||
/// </summary>
|
||||
public CarStatus Status { get; set; }
|
||||
|
||||
public virtual Brand Brand { get; set; } = null!;
|
||||
|
||||
|
@ -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<RentalbusinessContext>(options => options.UseNpgsql(builder.Configuration.GetConnectionString("ASPDB")));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
@ -5,5 +5,8 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"ASPDB": "Host=localhost;Database=local;Username=postgres;Password="
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user