diff --git a/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs b/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs
index c14ca57..5088a41 100644
--- a/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs
+++ b/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs
@@ -9,7 +9,7 @@ namespace AutoWorkshopDatabaseImplement
{
if (OptionsBuilder.IsConfigured == false)
{
- OptionsBuilder.UseNpgsql(@"Host=localhost;Database=AutoWorkshop_Hard;Username=postgres;Password=admin");
+ OptionsBuilder.UseNpgsql(@"Host=localhost;Port=5000;Database=AutoWorkshop_Hard;Username=postgres;Password=admin");
}
base.OnConfiguring(OptionsBuilder);
diff --git a/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs b/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs
new file mode 100644
index 0000000..ac63286
--- /dev/null
+++ b/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.Designer.cs
@@ -0,0 +1,250 @@
+//
+using System;
+using AutoWorkshopDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace AutoWorkshopDatabaseImplement.Migrations
+{
+ [DbContext(typeof(AutoWorkshopDatabase))]
+ [Migration("20240505173724_Fix Shop-Repair relationship")]
+ partial class FixShopRepairrelationship
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.17")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Cost")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("DateCreate")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("DateImplement")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("RepairId")
+ .HasColumnType("integer");
+
+ b.Property("Status")
+ .HasColumnType("integer");
+
+ b.Property("Sum")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RepairId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Price")
+ .HasColumnType("double precision");
+
+ b.Property("RepairName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Repairs");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ComponentId")
+ .HasColumnType("integer");
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("RepairId")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComponentId");
+
+ b.HasIndex("RepairId");
+
+ b.ToTable("RepairComponents");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Address")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("OpeningDate")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("RepairsMaxCount")
+ .HasColumnType("integer");
+
+ b.Property("ShopName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Shops");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("RepairId")
+ .HasColumnType("integer");
+
+ b.Property("ShopId")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RepairId");
+
+ b.HasIndex("ShopId");
+
+ b.ToTable("ShopRepairs");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
+ .WithMany("Orders")
+ .HasForeignKey("RepairId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Repair");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.RepairComponent", b =>
+ {
+ b.HasOne("AutoWorkshopDatabaseImplement.Models.Component", "Component")
+ .WithMany("RepairComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
+ .WithMany("Components")
+ .HasForeignKey("RepairId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Component");
+
+ b.Navigation("Repair");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
+ {
+ b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
+ .WithMany("Shops")
+ .HasForeignKey("RepairId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AutoWorkshopDatabaseImplement.Models.Shop", "Shop")
+ .WithMany("Repairs")
+ .HasForeignKey("ShopId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Repair");
+
+ b.Navigation("Shop");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("RepairComponents");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+
+ b.Navigation("Shops");
+ });
+
+ modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
+ {
+ b.Navigation("Repairs");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.cs b/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.cs
new file mode 100644
index 0000000..1738a1e
--- /dev/null
+++ b/AutoWorkshopDatabaseImplement/Migrations/20240505173724_Fix Shop-Repair relationship.cs
@@ -0,0 +1,22 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace AutoWorkshopDatabaseImplement.Migrations
+{
+ ///
+ public partial class FixShopRepairrelationship : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
diff --git a/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs b/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs
index 454b66c..7dc1d54 100644
--- a/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs
+++ b/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs
@@ -207,7 +207,7 @@ namespace AutoWorkshopDatabaseImplement.Migrations
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.ShopRepair", b =>
{
b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair")
- .WithMany()
+ .WithMany("Shops")
.HasForeignKey("RepairId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -233,6 +233,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations
b.Navigation("Components");
b.Navigation("Orders");
+
+ b.Navigation("Shops");
});
modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Shop", b =>
diff --git a/AutoWorkshopDatabaseImplement/Models/Repair.cs b/AutoWorkshopDatabaseImplement/Models/Repair.cs
index e4707ba..b98ccb8 100644
--- a/AutoWorkshopDatabaseImplement/Models/Repair.cs
+++ b/AutoWorkshopDatabaseImplement/Models/Repair.cs
@@ -38,7 +38,10 @@ namespace AutoWorkshopDatabaseImplement.Models
[ForeignKey("RepairId")]
public virtual List Orders { get; set; } = new();
-
+
+ [ForeignKey("RepairId")]
+ public virtual List Shops { get; set; } = new();
+
public static Repair Create(AutoWorkshopDatabase Context, RepairBindingModel Model)
{
return new Repair()
diff --git a/AutoWorkshopDatabaseImplement/Models/Shop.cs b/AutoWorkshopDatabaseImplement/Models/Shop.cs
index 59aef6c..63f60b8 100644
--- a/AutoWorkshopDatabaseImplement/Models/Shop.cs
+++ b/AutoWorkshopDatabaseImplement/Models/Shop.cs
@@ -1,6 +1,7 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AutoWorkshopDatabaseImplement.Models
@@ -8,17 +9,25 @@ namespace AutoWorkshopDatabaseImplement.Models
public class Shop : IShopModel
{
public int Id { get; set; }
-
+
+ [Required]
public string ShopName { get; set; } = string.Empty;
+ [Required]
public string Address { get; set; } = string.Empty;
+ [Required]
public DateTime OpeningDate { get; set; }
+ [Required]
public int RepairsMaxCount { get; set; }
+ [ForeignKey("ShopId")]
+ public List Repairs { get; set; } = new();
+
private Dictionary? _shopRepairs = null;
+ [NotMapped]
public Dictionary ShopRepairs
{
get
@@ -36,9 +45,6 @@ namespace AutoWorkshopDatabaseImplement.Models
}
}
- [ForeignKey("ShopId")]
- public List Repairs { get; set; } = new();
-
public static Shop Create(AutoWorkshopDatabase Context, ShopBindingModel Model)
{
return new Shop()