fix database
This commit is contained in:
parent
687e4a8e55
commit
22f762b60b
@ -9,7 +9,6 @@ namespace CarShowroomDataModels.Models
|
||||
public interface IClient : IId
|
||||
{
|
||||
string Name { get; }
|
||||
string Email { get; }
|
||||
string Password { get; }
|
||||
string PhoneNumber { get; }
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="SearchModel\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -11,14 +11,12 @@ namespace CarShowroomContracts.Dtos
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string PhoneNumber { get; set; }
|
||||
public ClientDto(IClient model)
|
||||
{
|
||||
Id = model.Id;
|
||||
Name = model.Name;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
PhoneNumber = model.PhoneNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,12 @@ namespace CarShowroomContracts.Views
|
||||
[DisplayName("ФИО")]
|
||||
public string Name { get; set; }
|
||||
[DisplayName("Email")]
|
||||
public string Email { get; set; }
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; }
|
||||
public string PhoneNumber { get; set; }
|
||||
public ClientView(IClient model)
|
||||
{
|
||||
Id = model.Id;
|
||||
Name = model.Name;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
PhoneNumber = model.PhoneNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ namespace CarShowroomDatabaseStorage
|
||||
modelBuilder.Entity<SaleService>().HasKey(sc => new { sc.SaleId, sc.ServiceId });
|
||||
//default values
|
||||
modelBuilder.Entity<Client>().Property(c => c.Name).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Client>().Property(c => c.Password).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Employee>().Property(e => e.Name).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Employee>().Property(e => e.Password).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Car>().Property(c => c.Color).HasDefaultValue("empty_string");
|
||||
|
@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
namespace CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("client")]
|
||||
[Index(nameof(Email), IsUnique = true)]
|
||||
[Index(nameof(PhoneNumber), IsUnique = true)]
|
||||
public class Client : IClient
|
||||
{
|
||||
[Column("client_id")]
|
||||
@ -23,13 +23,9 @@ namespace CarShowroomDatabaseStorage.Entities
|
||||
[MaxLength(50)]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("client_email")]
|
||||
[MaxLength(40)]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("client_password")]
|
||||
[MaxLength(32)]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[Column("client_phonenumber")]
|
||||
[MaxLength(25)]
|
||||
public string PhoneNumber { get; private set; } = string.Empty;
|
||||
public virtual List<Sale> Sales { get; set; } = new();
|
||||
|
||||
private Client() { }
|
||||
@ -38,8 +34,7 @@ namespace CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
Id = client.Id;
|
||||
Name = client.Name;
|
||||
Email = client.Email;
|
||||
Password = client.Password;
|
||||
PhoneNumber = client.PhoneNumber;
|
||||
}
|
||||
|
||||
public static Client? Create(IClient client)
|
||||
@ -54,8 +49,7 @@ namespace CarShowroomDatabaseStorage.Entities
|
||||
if (client == null)
|
||||
return;
|
||||
Name = client.Name;
|
||||
Email = client.Email;
|
||||
Password = client.Password;
|
||||
PhoneNumber = client.PhoneNumber;
|
||||
}
|
||||
|
||||
public ClientView GetClientView()
|
||||
|
@ -28,24 +28,22 @@ namespace CarShowroomDatabaseStorage.Entities
|
||||
[Column("sale_employee_id")]
|
||||
public int? EmployeeId { get; private set; }
|
||||
public virtual Employee? Employee { get; set; }
|
||||
public virtual List<Car> Cars { get; set; } = new();
|
||||
public virtual List<SaleCar> SaleCars { get; set; } = new();
|
||||
[NotMapped]
|
||||
public List<int> CarIds
|
||||
{
|
||||
get
|
||||
{
|
||||
return Cars.Select(c => c.Id).ToList();
|
||||
return SaleCars.Select(c => c.CarId).ToList();
|
||||
}
|
||||
}
|
||||
public virtual List<Service> Services { get; set; } = new();
|
||||
public virtual List<SaleService> SaleServices { get; set; } = new();
|
||||
[NotMapped]
|
||||
public List<int> ServiceIds
|
||||
{
|
||||
get
|
||||
{
|
||||
return Services.Select(s => s.Id).ToList();
|
||||
return SaleServices.Select(s => s.ServiceId).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,8 +84,8 @@ namespace CarShowroomDatabaseStorage.Entities
|
||||
SaleView sale = new SaleView(this);
|
||||
sale.ClientName = Client?.Name ?? string.Empty;
|
||||
sale.EmployeeName = Employee?.Name ?? string.Empty;
|
||||
sale.Services = Services.Select(s => s.GetServiceView()).ToList();
|
||||
sale.Cars = Cars.Select(c => c.GetCarView()).ToList();
|
||||
sale.Services = SaleServices.Select(s => s.Service.GetServiceView()).ToList();
|
||||
sale.Cars = SaleCars.Select(c => c.Car.GetCarView()).ToList();
|
||||
return sale;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace CarShowroomDatabaseStorage.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarShowroomDatabase))]
|
||||
[Migration("20240505145552_InitialCreate")]
|
||||
[Migration("20240505165914_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -50,15 +50,10 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("car_releasedate");
|
||||
|
||||
b.Property<int?>("SaleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ModelId");
|
||||
|
||||
b.HasIndex("SaleId");
|
||||
|
||||
b.ToTable("car");
|
||||
});
|
||||
|
||||
@ -71,12 +66,6 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("client_email");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -85,17 +74,15 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("client_name");
|
||||
|
||||
b.Property<string>("Password")
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("client_password");
|
||||
.HasMaxLength(25)
|
||||
.HasColumnType("character varying(25)")
|
||||
.HasColumnName("client_phonenumber");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
b.HasIndex("PhoneNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("client");
|
||||
@ -289,16 +276,11 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("service_name");
|
||||
|
||||
b.Property<int?>("SaleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("SaleId");
|
||||
|
||||
b.ToTable("service");
|
||||
});
|
||||
|
||||
@ -310,10 +292,6 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", null)
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("SaleId");
|
||||
|
||||
b.Navigation("Model");
|
||||
});
|
||||
|
||||
@ -383,13 +361,6 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("SaleId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||
{
|
||||
b.Navigation("SaleCars");
|
||||
@ -417,13 +388,9 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Sale", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
|
||||
b.Navigation("SaleCars");
|
||||
|
||||
b.Navigation("SaleServices");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
@ -19,8 +19,7 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
client_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
client_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
||||
client_email = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
|
||||
client_password = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, defaultValue: "empty_string")
|
||||
client_phonenumber = table.Column<string>(type: "character varying(25)", maxLength: 25, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -55,6 +54,20 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
table.PrimaryKey("PK_make", x => x.make_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "service",
|
||||
columns: table => new
|
||||
{
|
||||
service_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
service_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
service_cost = table.Column<int>(type: "integer", nullable: false, defaultValue: -1)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_service", x => x.service_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "sale",
|
||||
columns: table => new
|
||||
@ -104,53 +117,6 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "service",
|
||||
columns: table => new
|
||||
{
|
||||
service_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
service_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
service_cost = table.Column<int>(type: "integer", nullable: false, defaultValue: -1),
|
||||
SaleId = table.Column<int>(type: "integer", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_service", x => x.service_id);
|
||||
table.ForeignKey(
|
||||
name: "FK_service_sale_SaleId",
|
||||
column: x => x.SaleId,
|
||||
principalTable: "sale",
|
||||
principalColumn: "sale_id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "car",
|
||||
columns: table => new
|
||||
{
|
||||
car_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
car_color = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
||||
car_releasedate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
car_model_id = table.Column<int>(type: "integer", nullable: false),
|
||||
SaleId = table.Column<int>(type: "integer", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_car", x => x.car_id);
|
||||
table.ForeignKey(
|
||||
name: "FK_car_model_car_model_id",
|
||||
column: x => x.car_model_id,
|
||||
principalTable: "model",
|
||||
principalColumn: "model_id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_car_sale_SaleId",
|
||||
column: x => x.SaleId,
|
||||
principalTable: "sale",
|
||||
principalColumn: "sale_id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "sale_service",
|
||||
columns: table => new
|
||||
@ -175,6 +141,27 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "car",
|
||||
columns: table => new
|
||||
{
|
||||
car_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
car_color = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
||||
car_releasedate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
car_model_id = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_car", x => x.car_id);
|
||||
table.ForeignKey(
|
||||
name: "FK_car_model_car_model_id",
|
||||
column: x => x.car_model_id,
|
||||
principalTable: "model",
|
||||
principalColumn: "model_id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "sale_car",
|
||||
columns: table => new
|
||||
@ -205,14 +192,9 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
column: "car_model_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_car_SaleId",
|
||||
table: "car",
|
||||
column: "SaleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_client_client_email",
|
||||
name: "IX_client_client_phonenumber",
|
||||
table: "client",
|
||||
column: "client_email",
|
||||
column: "client_phonenumber",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
@ -258,11 +240,6 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
table: "sale_service",
|
||||
column: "service_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_service_SaleId",
|
||||
table: "service",
|
||||
column: "SaleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_service_service_name",
|
||||
table: "service",
|
||||
@ -282,23 +259,23 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "car");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "sale");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "service");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "model");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "sale");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "make");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "client");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "employee");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "make");
|
||||
}
|
||||
}
|
||||
}
|
@ -47,15 +47,10 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("car_releasedate");
|
||||
|
||||
b.Property<int?>("SaleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ModelId");
|
||||
|
||||
b.HasIndex("SaleId");
|
||||
|
||||
b.ToTable("car");
|
||||
});
|
||||
|
||||
@ -68,12 +63,6 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("client_email");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -82,17 +71,15 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("client_name");
|
||||
|
||||
b.Property<string>("Password")
|
||||
b.Property<string>("PhoneNumber")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("client_password");
|
||||
.HasMaxLength(25)
|
||||
.HasColumnType("character varying(25)")
|
||||
.HasColumnName("client_phonenumber");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
b.HasIndex("PhoneNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("client");
|
||||
@ -286,16 +273,11 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("service_name");
|
||||
|
||||
b.Property<int?>("SaleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("SaleId");
|
||||
|
||||
b.ToTable("service");
|
||||
});
|
||||
|
||||
@ -307,10 +289,6 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", null)
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("SaleId");
|
||||
|
||||
b.Navigation("Model");
|
||||
});
|
||||
|
||||
@ -380,13 +358,6 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("SaleId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||
{
|
||||
b.Navigation("SaleCars");
|
||||
@ -414,13 +385,9 @@ namespace CarShowroomDatabaseStorage.Migrations
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Sale", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
|
||||
b.Navigation("SaleCars");
|
||||
|
||||
b.Navigation("SaleServices");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
|
Binary file not shown.
BIN
ERD/car-showroom_2.vpp.bak_007d
Normal file
BIN
ERD/car-showroom_2.vpp.bak_007d
Normal file
Binary file not shown.
BIN
ERD/car-showroom_2.vpp.bak_008d
Normal file
BIN
ERD/car-showroom_2.vpp.bak_008d
Normal file
Binary file not shown.
BIN
ERD/car-showroom_2.vpp.bak_009d
Normal file
BIN
ERD/car-showroom_2.vpp.bak_009d
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user