diff --git a/CarShowroom/CarShowroomDataModels/AbstractModels/IClient.cs b/CarShowroom/CarShowroomDataModels/AbstractModels/IClient.cs index 8f298d2..2c6b3d7 100644 --- a/CarShowroom/CarShowroomDataModels/AbstractModels/IClient.cs +++ b/CarShowroom/CarShowroomDataModels/AbstractModels/IClient.cs @@ -9,7 +9,6 @@ namespace CarShowroomDataModels.Models public interface IClient : IId { string Name { get; } - string Email { get; } - string Password { get; } + string PhoneNumber { get; } } } diff --git a/CarShowroom/CarShowroomDataModels/CarShowroomDataModels.csproj b/CarShowroom/CarShowroomDataModels/CarShowroomDataModels.csproj index 132c02c..0e82290 100644 --- a/CarShowroom/CarShowroomDataModels/CarShowroomDataModels.csproj +++ b/CarShowroom/CarShowroomDataModels/CarShowroomDataModels.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/CarShowroom/CarShowroomDataModels/Dtos/ClientDto.cs b/CarShowroom/CarShowroomDataModels/Dtos/ClientDto.cs index 0584e8e..46cf584 100644 --- a/CarShowroom/CarShowroomDataModels/Dtos/ClientDto.cs +++ b/CarShowroom/CarShowroomDataModels/Dtos/ClientDto.cs @@ -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; } } } diff --git a/CarShowroom/CarShowroomDataModels/Views/ClientView.cs b/CarShowroom/CarShowroomDataModels/Views/ClientView.cs index 4d7e47f..45eba04 100644 --- a/CarShowroom/CarShowroomDataModels/Views/ClientView.cs +++ b/CarShowroom/CarShowroomDataModels/Views/ClientView.cs @@ -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; } } } diff --git a/CarShowroom/CarShowroomDatabaseStorage/CarShowroomDatabase.cs b/CarShowroom/CarShowroomDatabaseStorage/CarShowroomDatabase.cs index bc09ec4..e8cffcc 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/CarShowroomDatabase.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/CarShowroomDatabase.cs @@ -30,7 +30,6 @@ namespace CarShowroomDatabaseStorage modelBuilder.Entity().HasKey(sc => new { sc.SaleId, sc.ServiceId }); //default values modelBuilder.Entity().Property(c => c.Name).HasDefaultValue("empty_string"); - modelBuilder.Entity().Property(c => c.Password).HasDefaultValue("empty_string"); modelBuilder.Entity().Property(e => e.Name).HasDefaultValue("empty_string"); modelBuilder.Entity().Property(e => e.Password).HasDefaultValue("empty_string"); modelBuilder.Entity().Property(c => c.Color).HasDefaultValue("empty_string"); diff --git a/CarShowroom/CarShowroomDatabaseStorage/Entities/Client.cs b/CarShowroom/CarShowroomDatabaseStorage/Entities/Client.cs index 5d15bc1..db3dcfd 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Entities/Client.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Entities/Client.cs @@ -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 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() diff --git a/CarShowroom/CarShowroomDatabaseStorage/Entities/Sale.cs b/CarShowroom/CarShowroomDatabaseStorage/Entities/Sale.cs index 67aa616..0a7798d 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Entities/Sale.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Entities/Sale.cs @@ -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 Cars { get; set; } = new(); public virtual List SaleCars { get; set; } = new(); [NotMapped] public List CarIds { get { - return Cars.Select(c => c.Id).ToList(); + return SaleCars.Select(c => c.CarId).ToList(); } } - public virtual List Services { get; set; } = new(); public virtual List SaleServices { get; set; } = new(); [NotMapped] public List 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; } } diff --git a/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505145552_InitialCreate.Designer.cs b/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505165914_InitialCreate.Designer.cs similarity index 90% rename from CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505145552_InitialCreate.Designer.cs rename to CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505165914_InitialCreate.Designer.cs index 659aa60..6104087 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505145552_InitialCreate.Designer.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505165914_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace CarShowroomDatabaseStorage.Migrations { [DbContext(typeof(CarShowroomDatabase))] - [Migration("20240505145552_InitialCreate")] + [Migration("20240505165914_InitialCreate")] partial class InitialCreate { /// @@ -50,15 +50,10 @@ namespace CarShowroomDatabaseStorage.Migrations .HasColumnType("timestamp with time zone") .HasColumnName("car_releasedate"); - b.Property("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("Id")); - b.Property("Email") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("character varying(40)") - .HasColumnName("client_email"); - b.Property("Name") .IsRequired() .ValueGeneratedOnAdd() @@ -85,17 +74,15 @@ namespace CarShowroomDatabaseStorage.Migrations .HasDefaultValue("empty_string") .HasColumnName("client_name"); - b.Property("Password") + b.Property("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("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 => diff --git a/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505145552_InitialCreate.cs b/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505165914_InitialCreate.cs similarity index 89% rename from CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505145552_InitialCreate.cs rename to CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505165914_InitialCreate.cs index 91cc743..9bd20a8 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505145552_InitialCreate.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505165914_InitialCreate.cs @@ -19,8 +19,7 @@ namespace CarShowroomDatabaseStorage.Migrations client_id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), client_name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"), - client_email = table.Column(type: "character varying(40)", maxLength: 40, nullable: false), - client_password = table.Column(type: "character varying(32)", maxLength: 32, nullable: false, defaultValue: "empty_string") + client_phonenumber = table.Column(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(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + service_name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + service_cost = table.Column(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(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - service_name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - service_cost = table.Column(type: "integer", nullable: false, defaultValue: -1), - SaleId = table.Column(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(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - car_color = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"), - car_releasedate = table.Column(type: "timestamp with time zone", nullable: false), - car_model_id = table.Column(type: "integer", nullable: false), - SaleId = table.Column(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(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + car_color = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"), + car_releasedate = table.Column(type: "timestamp with time zone", nullable: false), + car_model_id = table.Column(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"); } } } diff --git a/CarShowroom/CarShowroomDatabaseStorage/Migrations/CarShowroomDatabaseModelSnapshot.cs b/CarShowroom/CarShowroomDatabaseStorage/Migrations/CarShowroomDatabaseModelSnapshot.cs index 3d8a044..49d2c2d 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Migrations/CarShowroomDatabaseModelSnapshot.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Migrations/CarShowroomDatabaseModelSnapshot.cs @@ -47,15 +47,10 @@ namespace CarShowroomDatabaseStorage.Migrations .HasColumnType("timestamp with time zone") .HasColumnName("car_releasedate"); - b.Property("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("Id")); - b.Property("Email") - .IsRequired() - .HasMaxLength(40) - .HasColumnType("character varying(40)") - .HasColumnName("client_email"); - b.Property("Name") .IsRequired() .ValueGeneratedOnAdd() @@ -82,17 +71,15 @@ namespace CarShowroomDatabaseStorage.Migrations .HasDefaultValue("empty_string") .HasColumnName("client_name"); - b.Property("Password") + b.Property("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("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 => diff --git a/ERD/car-showroom_2.vpp b/ERD/car-showroom_2.vpp index c7362fc..5319f3b 100644 Binary files a/ERD/car-showroom_2.vpp and b/ERD/car-showroom_2.vpp differ diff --git a/ERD/car-showroom_2.vpp.bak_007d b/ERD/car-showroom_2.vpp.bak_007d new file mode 100644 index 0000000..158383e Binary files /dev/null and b/ERD/car-showroom_2.vpp.bak_007d differ diff --git a/ERD/car-showroom_2.vpp.bak_008d b/ERD/car-showroom_2.vpp.bak_008d new file mode 100644 index 0000000..245fe52 Binary files /dev/null and b/ERD/car-showroom_2.vpp.bak_008d differ diff --git a/ERD/car-showroom_2.vpp.bak_009d b/ERD/car-showroom_2.vpp.bak_009d new file mode 100644 index 0000000..2859c33 Binary files /dev/null and b/ERD/car-showroom_2.vpp.bak_009d differ