diff --git a/ServiceStation/ServiceStation/Form1.Designer.cs b/ServiceStation/ServiceStation/Form1.Designer.cs index 6a94a0e..583e52d 100644 --- a/ServiceStation/ServiceStation/Form1.Designer.cs +++ b/ServiceStation/ServiceStation/Form1.Designer.cs @@ -28,32 +28,18 @@ /// private void InitializeComponent() { - button1 = new Button(); SuspendLayout(); // - // button1 - // - button1.Location = new Point(352, 192); - button1.Name = "button1"; - button1.Size = new Size(75, 23); - button1.TabIndex = 0; - button1.Text = "button1"; - button1.UseVisualStyleBackColor = true; - button1.Click += button1_Click; - // // Form1 // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); - Controls.Add(button1); Name = "Form1"; Text = "Form1"; ResumeLayout(false); } #endregion - - private Button button1; } } diff --git a/ServiceStation/ServiceStation/Form1.cs b/ServiceStation/ServiceStation/Form1.cs index 5b68768..0c6a8ee 100644 --- a/ServiceStation/ServiceStation/Form1.cs +++ b/ServiceStation/ServiceStation/Form1.cs @@ -1,6 +1,8 @@ using ServiceStationContracts.BindingModels; using ServiceStationContracts.BusinessLogicsContracts; using ServiceStationContracts.SearchModels; +using ServiceStationContracts.StoragesContracts; +using ServiceStationContracts.ViewModels; using ServiceStationDatabaseImplement; using ServiceStationDatabaseImplement.Models; using ServiceStationDataModels.Enums; @@ -10,16 +12,9 @@ namespace ServiceStation { public partial class Form1 : Form { - private readonly IRepairLogic _logic; - public Form1(IRepairLogic logic, ICarLogic clogic) + public Form1() { InitializeComponent(); - _logic = logic; - } - - private void button1_Click(object sender, EventArgs e) - { - } } } diff --git a/ServiceStation/ServiceStationContracts/BindingModels/TechnicalWorkBindingModel.cs b/ServiceStation/ServiceStationContracts/BindingModels/TechnicalWorkBindingModel.cs index b55a716..9a21f50 100644 --- a/ServiceStation/ServiceStationContracts/BindingModels/TechnicalWorkBindingModel.cs +++ b/ServiceStation/ServiceStationContracts/BindingModels/TechnicalWorkBindingModel.cs @@ -20,7 +20,5 @@ namespace ServiceStationContracts.BindingModels public int ExecutorId { get; set; } public Dictionary TechnicalWorkCars { get; set; } = new(); - - public int? WorkId { get; set; } } } diff --git a/ServiceStation/ServiceStationContracts/BindingModels/WorkBindingModel.cs b/ServiceStation/ServiceStationContracts/BindingModels/WorkBindingModel.cs index 2a958f0..43c57c0 100644 --- a/ServiceStation/ServiceStationContracts/BindingModels/WorkBindingModel.cs +++ b/ServiceStation/ServiceStationContracts/BindingModels/WorkBindingModel.cs @@ -20,6 +20,8 @@ namespace ServiceStationContracts.BindingModels public int GuarantorId { get; set; } + public int? TechnicalWorkId { get; set; } + public Dictionary WorkSpareParts { get; set; } = new(); } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/CarViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/CarViewModel.cs index de04054..98c0328 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/CarViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/CarViewModel.cs @@ -19,9 +19,5 @@ namespace ServiceStationContracts.ViewModels public string CarBrand { get; set; } = string.Empty; public int ExecutorId { get; set; } - - public Dictionary CarDefects { get; set; } = new(); - - public Dictionary CarTechnicalWorks { get; set; } = new(); } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/TechnicalWorkViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/TechnicalWorkViewModel.cs index 78ae417..7d01462 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/TechnicalWorkViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/TechnicalWorkViewModel.cs @@ -21,7 +21,5 @@ namespace ServiceStationContracts.ViewModels public int ExecutorId { get; set; } public Dictionary TechnicalWorkCars { get; set; } = new(); - - public int? WorkId { get; set; } } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs index c932b61..2a47418 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/WorkViewModel.cs @@ -1,11 +1,7 @@ using ServiceStationDataModels.Enums; using ServiceStationDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace ServiceStationContracts.ViewModels { @@ -24,6 +20,8 @@ namespace ServiceStationContracts.ViewModels public int GuarantorId { get; set; } - public Dictionary WorkSpareParts { get; } = new(); + public int? TechnicalWorkId { get; set; } + + public Dictionary WorkSpareParts { get; set; } = new(); } } diff --git a/ServiceStation/ServiceStationDataModels/Models/IRepairModel.cs b/ServiceStation/ServiceStationDataModels/Models/IRepairModel.cs index df50c1a..fba182b 100644 --- a/ServiceStation/ServiceStationDataModels/Models/IRepairModel.cs +++ b/ServiceStation/ServiceStationDataModels/Models/IRepairModel.cs @@ -16,8 +16,6 @@ namespace ServiceStationDataModels.Models int GuarantorId { get; } - int? DefectId { get; } - public Dictionary RepairSpareParts { get; } } } diff --git a/ServiceStation/ServiceStationDataModels/Models/ITechnicalWorkModel.cs b/ServiceStation/ServiceStationDataModels/Models/ITechnicalWorkModel.cs index 569483f..27bb6ec 100644 --- a/ServiceStation/ServiceStationDataModels/Models/ITechnicalWorkModel.cs +++ b/ServiceStation/ServiceStationDataModels/Models/ITechnicalWorkModel.cs @@ -12,7 +12,6 @@ namespace ServiceStationDataModels.Models DateTime? DateStartWork { get; } double WorkPrice { get; } int ExecutorId { get; } - int? WorkId { get; } public Dictionary TechnicalWorkCars { get; } } } diff --git a/ServiceStation/ServiceStationDataModels/Models/IWorkModel.cs b/ServiceStation/ServiceStationDataModels/Models/IWorkModel.cs index c413a71..f691acc 100644 --- a/ServiceStation/ServiceStationDataModels/Models/IWorkModel.cs +++ b/ServiceStation/ServiceStationDataModels/Models/IWorkModel.cs @@ -16,6 +16,8 @@ namespace ServiceStationDataModels.Models int GuarantorId { get; } + int? TechnicalWorkId { get; } + public Dictionary WorkSpareParts { get; } } } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/DefectStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/DefectStorage.cs index d26968a..082b095 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/DefectStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/DefectStorage.cs @@ -23,7 +23,7 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarTechnicalWorks) .ThenInclude(x => x.TechnicalWork) - .Include(x => x.Repairs) + .Include(x => x.Repair) .Include(x => x.Executor) .Select(x => x.GetViewModel) .ToList(); @@ -41,7 +41,7 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarTechnicalWorks) .ThenInclude(x => x.TechnicalWork) - .Include(x => x.Repairs) + .Include(x => x.Repair) .Include(x => x.Executor) .Where(x => x.ExecutorId == model.ExecutorId) .ToList() @@ -53,7 +53,7 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarTechnicalWorks) .ThenInclude(x => x.TechnicalWork) - .Include(x => x.Repairs) + .Include(x => x.Repair) .Include(x => x.Executor) .Where(x => x.DefectType == model.DefectType) .ToList() @@ -72,7 +72,7 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarTechnicalWorks) .ThenInclude(x => x.TechnicalWork) - .Include(x => x.Repairs) + .Include(x => x.Repair) .Include(x => x.Executor) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.DefectType) && x.DefectType == model.DefectType) || (model.Id.HasValue && x.Id == model.Id))? .GetViewModel; @@ -98,7 +98,7 @@ namespace ServiceStationDatabaseImplement.Implements if (elem == null) return null; elem.Update(model); context.SaveChanges(); - if (model.DefectCars != null) elem.UpdateCars(context, model); + if (model.DefectCars.Count != 0) elem.UpdateCars(context, model); transaction.Commit(); return elem.GetViewModel; } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/ExecutorStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/ExecutorStorage.cs index 5a3db9a..f87bce2 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/ExecutorStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/ExecutorStorage.cs @@ -25,14 +25,14 @@ namespace ServiceStationDatabaseImplement.Implements public List GetFilteredList(ExecutorSearchModel model) { - if (string.IsNullOrEmpty(model.ExecutorFIO)) return new(); + if (string.IsNullOrEmpty(model.ExecutorNumber)) return new(); using var context = new ServiceStationDatabase(); return context.Executors .Include(x => x.Cars) .Include(x => x.Defects) .Include(x => x.TechnicalWorks) - .Where(x => x.ExecutorFIO.Contains(model.ExecutorFIO)) + .Where(x => x.ExecutorNumber.Contains(model.ExecutorNumber)) .Select(x => x.GetViewModel) .ToList(); } @@ -40,15 +40,15 @@ namespace ServiceStationDatabaseImplement.Implements public ExecutorViewModel? GetElement(ExecutorSearchModel model) { using var context = new ServiceStationDatabase(); - if (!model.Id.HasValue && !string.IsNullOrEmpty(model.ExecutorFIO)) return null; + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ExecutorNumber)) return null; - if (!string.IsNullOrEmpty(model.ExecutorFIO)) + if (!string.IsNullOrEmpty(model.ExecutorNumber)) { return context.Executors .Include(x => x.Cars) .Include(x => x.Defects) .Include(x => x.TechnicalWorks) - .FirstOrDefault(x => x.ExecutorFIO.Contains(model.ExecutorFIO))? + .FirstOrDefault(x => x.ExecutorNumber.Contains(model.ExecutorNumber))? .GetViewModel; } return context.Executors diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs index 33bc645..a0db03a 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs @@ -22,7 +22,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePartWorks) .ThenInclude(x => x.Work) - //.Include(x => x.Defect) .Include(x => x.Guarantor) .Select(x => x.GetViewModel) .ToList(); @@ -40,7 +39,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePartWorks) .ThenInclude(x => x.Work) - //.Include(x => x.Defect) .Include(x => x.Guarantor) .Where(x => x.GuarantorId == model.GuarantorId) .ToList() @@ -52,7 +50,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePartWorks) .ThenInclude(x => x.Work) - //.Include(x => x.Defect) .Include(x => x.Guarantor) .Where(x => x.RepairName == model.RepairName) .ToList() @@ -71,7 +68,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePartWorks) .ThenInclude(x => x.Work) - //.Include(x => x.Defect) .Include(x => x.Guarantor) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.RepairName) && x.RepairName == model.RepairName) || (model.Id.HasValue && x.Id == model.Id))? .GetViewModel; diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/TechnicalWorkStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/TechnicalWorkStorage.cs index 3b9fc0c..4c4d94e 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/TechnicalWorkStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/TechnicalWorkStorage.cs @@ -23,7 +23,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarDefects) .ThenInclude(x => x.Defect) - .Include(x => x.Work) .Include(x => x.Executor) .ToList() .Select(x => x.GetViewModel) @@ -45,7 +44,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarDefects) .ThenInclude(x => x.Defect) - .Include(x => x.Work) .Include(x => x.Executor) .Where(x => x.DateStartWork >= model.DateFrom && x.DateStartWork <= model.DateTo && x.ExecutorId == model.ExecutorId) .Select(x => x.GetViewModel) @@ -58,7 +56,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarDefects) .ThenInclude(x => x.Defect) - .Include(x => x.Work) .Include(x => x.Executor) .Where(x => x.ExecutorId == model.ExecutorId) .ToList() @@ -70,7 +67,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarDefects) .ThenInclude(x => x.Defect) - .Include(x => x.Work) .Include(x => x.Executor) .Where(x => x.WorkType.Contains(model.WorkType)) .ToList() @@ -88,7 +84,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.Car) .ThenInclude(x => x.CarDefects) .ThenInclude(x => x.Defect) - .Include(x => x.Work) .Include(x => x.Executor) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkType) && x.WorkType == model.WorkType) || (model.Id.HasValue && x.Id == model.Id))? .GetViewModel; diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/WorkStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/WorkStorage.cs index fe07e04..f0a4107 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/WorkStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/WorkStorage.cs @@ -44,7 +44,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePartRepairs) .ThenInclude(x => x.Repair) - //.Include(x => x.TechnicalWork) .Include(x => x.Guarantor) .Where(x => x.GuarantorId == model.GuarantorId) .Select(x => x.GetViewModel) @@ -57,7 +56,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePartRepairs) .ThenInclude(x => x.Repair) - //.Include(x => x.TechnicalWork) .Include(x => x.Guarantor) .Where(x => x.GuarantorId == model.GuarantorId) .ToList() @@ -69,7 +67,6 @@ namespace ServiceStationDatabaseImplement.Implements .ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePartRepairs) .ThenInclude(x => x.Repair) - //.Include(x => x.TechnicalWork) .Include(x => x.Guarantor) .Where(x => x.WorkName.Contains(model.WorkName)) .ToList() @@ -82,15 +79,15 @@ namespace ServiceStationDatabaseImplement.Implements if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue) return null; using var context = new ServiceStationDatabase(); - return context.Works + var elem = context.Works .Include(x => x.SpareParts) .ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePartRepairs) .ThenInclude(x => x.Repair) - //.Include(x => x.TechnicalWork) .Include(x => x.Guarantor) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkName) && x.WorkName == model.WorkName) || (model.Id.HasValue && x.Id == model.Id))? - .GetViewModel; + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkName) && x.WorkName == model.WorkName) || (model.Id.HasValue && x.Id == model.Id)); + + return elem?.GetViewModel; } public WorkViewModel? Insert(WorkBindingModel model) @@ -116,7 +113,7 @@ namespace ServiceStationDatabaseImplement.Implements elem.Update(model); context.SaveChanges(); - if (model.WorkSpareParts != null) elem.UpdateSpareParts(context, model); + if (model.WorkSpareParts.Count != 0) elem.UpdateSpareParts(context, model); transaction.Commit(); return elem.GetViewModel; } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428155629_InitMigration.Designer.cs b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.Designer.cs similarity index 96% rename from ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428155629_InitMigration.Designer.cs rename to ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.Designer.cs index 2ead8c3..a5f4dd0 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428155629_InitMigration.Designer.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.Designer.cs @@ -12,7 +12,7 @@ using ServiceStationDatabaseImplement; namespace ServiceStationDatabaseImplement.Migrations { [DbContext(typeof(ServiceStationDatabase))] - [Migration("20240428155629_InitMigration")] + [Migration("20240428190245_InitMigration")] partial class InitMigration { /// @@ -115,10 +115,15 @@ namespace ServiceStationDatabaseImplement.Migrations b.Property("ExecutorId") .HasColumnType("int"); + b.Property("RepairId") + .HasColumnType("int"); + b.HasKey("Id"); b.HasIndex("ExecutorId"); + b.HasIndex("RepairId"); + b.ToTable("Defects"); }); @@ -186,9 +191,6 @@ namespace ServiceStationDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("DefectId") - .HasColumnType("int"); - b.Property("GuarantorId") .HasColumnType("int"); @@ -204,8 +206,6 @@ namespace ServiceStationDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("DefectId"); - b.HasIndex("GuarantorId"); b.ToTable("Repairs"); @@ -296,9 +296,6 @@ namespace ServiceStationDatabaseImplement.Migrations b.Property("ExecutorId") .HasColumnType("int"); - b.Property("WorkId") - .HasColumnType("int"); - b.Property("WorkPrice") .HasColumnType("float"); @@ -310,8 +307,6 @@ namespace ServiceStationDatabaseImplement.Migrations b.HasIndex("ExecutorId"); - b.HasIndex("WorkId"); - b.ToTable("TechnicalWorks"); }); @@ -329,6 +324,9 @@ namespace ServiceStationDatabaseImplement.Migrations b.Property("Status") .HasColumnType("int"); + b.Property("TechnicalWorkId") + .HasColumnType("int"); + b.Property("WorkName") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -340,6 +338,8 @@ namespace ServiceStationDatabaseImplement.Migrations b.HasIndex("GuarantorId"); + b.HasIndex("TechnicalWorkId"); + b.ToTable("Works"); }); @@ -400,23 +400,23 @@ namespace ServiceStationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ServiceStationDatabaseImplement.Models.Repair", "Repair") + .WithMany("Defects") + .HasForeignKey("RepairId"); + b.Navigation("Executor"); + + b.Navigation("Repair"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => { - b.HasOne("ServiceStationDatabaseImplement.Models.Defect", "Defect") - .WithMany("Repairs") - .HasForeignKey("DefectId"); - b.HasOne("ServiceStationDatabaseImplement.Models.Guarantor", "Guarantor") .WithMany("Repairs") .HasForeignKey("GuarantorId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("Defect"); - b.Navigation("Guarantor"); }); @@ -477,13 +477,7 @@ namespace ServiceStationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("ServiceStationDatabaseImplement.Models.Work", "Work") - .WithMany("TechnicalWorks") - .HasForeignKey("WorkId"); - b.Navigation("Executor"); - - b.Navigation("Work"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => @@ -494,7 +488,13 @@ namespace ServiceStationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ServiceStationDatabaseImplement.Models.TechnicalWork", "TechnicalWork") + .WithMany("Works") + .HasForeignKey("TechnicalWorkId"); + b.Navigation("Guarantor"); + + b.Navigation("TechnicalWork"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Car", b => @@ -507,8 +507,6 @@ namespace ServiceStationDatabaseImplement.Migrations modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b => { b.Navigation("Cars"); - - b.Navigation("Repairs"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Executor", b => @@ -531,6 +529,8 @@ namespace ServiceStationDatabaseImplement.Migrations modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => { + b.Navigation("Defects"); + b.Navigation("SpareParts"); }); @@ -544,13 +544,13 @@ namespace ServiceStationDatabaseImplement.Migrations modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b => { b.Navigation("Cars"); + + b.Navigation("Works"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => { b.Navigation("SpareParts"); - - b.Navigation("TechnicalWorks"); }); #pragma warning restore 612, 618 } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428155629_InitMigration.cs b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.cs similarity index 95% rename from ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428155629_InitMigration.cs rename to ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.cs index 5cc27d4..30b713c 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428155629_InitMigration.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240428190245_InitMigration.cs @@ -65,26 +65,49 @@ namespace ServiceStationDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "Defects", + name: "TechnicalWorks", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - DefectType = table.Column(type: "nvarchar(max)", nullable: false), - DefectPrice = table.Column(type: "float", nullable: false), + WorkType = table.Column(type: "nvarchar(max)", nullable: false), + DateStartWork = table.Column(type: "datetime2", nullable: true), + WorkPrice = table.Column(type: "float", nullable: false), ExecutorId = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Defects", x => x.Id); + table.PrimaryKey("PK_TechnicalWorks", x => x.Id); table.ForeignKey( - name: "FK_Defects_Executors_ExecutorId", + name: "FK_TechnicalWorks_Executors_ExecutorId", column: x => x.ExecutorId, principalTable: "Executors", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "Repairs", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RepairName = table.Column(type: "nvarchar(max)", nullable: false), + Status = table.Column(type: "int", nullable: false), + RepairPrice = table.Column(type: "float", nullable: false), + GuarantorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Repairs", x => x.Id); + table.ForeignKey( + name: "FK_Repairs_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "SpareParts", columns: table => new @@ -106,6 +129,32 @@ namespace ServiceStationDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "CarTechnicalWorks", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CarId = table.Column(type: "int", nullable: false), + TechnicalWorkId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CarTechnicalWorks", x => x.Id); + table.ForeignKey( + name: "FK_CarTechnicalWorks_Cars_CarId", + column: x => x.CarId, + principalTable: "Cars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CarTechnicalWorks_TechnicalWorks_TechnicalWorkId", + column: x => x.TechnicalWorkId, + principalTable: "TechnicalWorks", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "Works", columns: table => new @@ -115,7 +164,8 @@ namespace ServiceStationDatabaseImplement.Migrations WorkName = table.Column(type: "nvarchar(max)", nullable: false), Status = table.Column(type: "int", nullable: false), WorkPrice = table.Column(type: "float", nullable: false), - GuarantorId = table.Column(type: "int", nullable: false) + GuarantorId = table.Column(type: "int", nullable: false), + TechnicalWorkId = table.Column(type: "int", nullable: true) }, constraints: table => { @@ -126,113 +176,37 @@ namespace ServiceStationDatabaseImplement.Migrations principalTable: "Guarantors", principalColumn: "Id", onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "CarDefects", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - CarId = table.Column(type: "int", nullable: false), - DefectId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CarDefects", x => x.Id); table.ForeignKey( - name: "FK_CarDefects_Cars_CarId", - column: x => x.CarId, - principalTable: "Cars", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_CarDefects_Defects_DefectId", - column: x => x.DefectId, - principalTable: "Defects", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "Repairs", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - RepairName = table.Column(type: "nvarchar(max)", nullable: false), - Status = table.Column(type: "int", nullable: false), - RepairPrice = table.Column(type: "float", nullable: false), - GuarantorId = table.Column(type: "int", nullable: false), - DefectId = table.Column(type: "int", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Repairs", x => x.Id); - table.ForeignKey( - name: "FK_Repairs_Defects_DefectId", - column: x => x.DefectId, - principalTable: "Defects", + name: "FK_Works_TechnicalWorks_TechnicalWorkId", + column: x => x.TechnicalWorkId, + principalTable: "TechnicalWorks", principalColumn: "Id"); - table.ForeignKey( - name: "FK_Repairs_Guarantors_GuarantorId", - column: x => x.GuarantorId, - principalTable: "Guarantors", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "SparePartWorks", + name: "Defects", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - SparePartId = table.Column(type: "int", nullable: false), - WorkId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_SparePartWorks", x => x.Id); - table.ForeignKey( - name: "FK_SparePartWorks_SpareParts_SparePartId", - column: x => x.SparePartId, - principalTable: "SpareParts", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_SparePartWorks_Works_WorkId", - column: x => x.WorkId, - principalTable: "Works", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "TechnicalWorks", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - WorkType = table.Column(type: "nvarchar(max)", nullable: false), - DateStartWork = table.Column(type: "datetime2", nullable: true), - WorkPrice = table.Column(type: "float", nullable: false), + DefectType = table.Column(type: "nvarchar(max)", nullable: false), + DefectPrice = table.Column(type: "float", nullable: false), ExecutorId = table.Column(type: "int", nullable: false), - WorkId = table.Column(type: "int", nullable: true) + RepairId = table.Column(type: "int", nullable: true) }, constraints: table => { - table.PrimaryKey("PK_TechnicalWorks", x => x.Id); + table.PrimaryKey("PK_Defects", x => x.Id); table.ForeignKey( - name: "FK_TechnicalWorks_Executors_ExecutorId", + name: "FK_Defects_Executors_ExecutorId", column: x => x.ExecutorId, principalTable: "Executors", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_TechnicalWorks_Works_WorkId", - column: x => x.WorkId, - principalTable: "Works", + name: "FK_Defects_Repairs_RepairId", + column: x => x.RepairId, + principalTable: "Repairs", principalColumn: "Id"); }); @@ -263,27 +237,53 @@ namespace ServiceStationDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "CarTechnicalWorks", + name: "SparePartWorks", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SparePartId = table.Column(type: "int", nullable: false), + WorkId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SparePartWorks", x => x.Id); + table.ForeignKey( + name: "FK_SparePartWorks_SpareParts_SparePartId", + column: x => x.SparePartId, + principalTable: "SpareParts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SparePartWorks_Works_WorkId", + column: x => x.WorkId, + principalTable: "Works", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "CarDefects", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CarId = table.Column(type: "int", nullable: false), - TechnicalWorkId = table.Column(type: "int", nullable: false) + DefectId = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_CarTechnicalWorks", x => x.Id); + table.PrimaryKey("PK_CarDefects", x => x.Id); table.ForeignKey( - name: "FK_CarTechnicalWorks_Cars_CarId", + name: "FK_CarDefects_Cars_CarId", column: x => x.CarId, principalTable: "Cars", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_CarTechnicalWorks_TechnicalWorks_TechnicalWorkId", - column: x => x.TechnicalWorkId, - principalTable: "TechnicalWorks", + name: "FK_CarDefects_Defects_DefectId", + column: x => x.DefectId, + principalTable: "Defects", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); @@ -319,9 +319,9 @@ namespace ServiceStationDatabaseImplement.Migrations column: "ExecutorId"); migrationBuilder.CreateIndex( - name: "IX_Repairs_DefectId", - table: "Repairs", - column: "DefectId"); + name: "IX_Defects_RepairId", + table: "Defects", + column: "RepairId"); migrationBuilder.CreateIndex( name: "IX_Repairs_GuarantorId", @@ -358,15 +358,15 @@ namespace ServiceStationDatabaseImplement.Migrations table: "TechnicalWorks", column: "ExecutorId"); - migrationBuilder.CreateIndex( - name: "IX_TechnicalWorks_WorkId", - table: "TechnicalWorks", - column: "WorkId"); - migrationBuilder.CreateIndex( name: "IX_Works_GuarantorId", table: "Works", column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_Works_TechnicalWorkId", + table: "Works", + column: "TechnicalWorkId"); } /// @@ -384,15 +384,12 @@ namespace ServiceStationDatabaseImplement.Migrations migrationBuilder.DropTable( name: "SparePartWorks"); + migrationBuilder.DropTable( + name: "Defects"); + migrationBuilder.DropTable( name: "Cars"); - migrationBuilder.DropTable( - name: "TechnicalWorks"); - - migrationBuilder.DropTable( - name: "Repairs"); - migrationBuilder.DropTable( name: "SpareParts"); @@ -400,7 +397,10 @@ namespace ServiceStationDatabaseImplement.Migrations name: "Works"); migrationBuilder.DropTable( - name: "Defects"); + name: "Repairs"); + + migrationBuilder.DropTable( + name: "TechnicalWorks"); migrationBuilder.DropTable( name: "Guarantors"); diff --git a/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs b/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs index d80956a..60d8c1b 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs @@ -112,10 +112,15 @@ namespace ServiceStationDatabaseImplement.Migrations b.Property("ExecutorId") .HasColumnType("int"); + b.Property("RepairId") + .HasColumnType("int"); + b.HasKey("Id"); b.HasIndex("ExecutorId"); + b.HasIndex("RepairId"); + b.ToTable("Defects"); }); @@ -183,9 +188,6 @@ namespace ServiceStationDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("DefectId") - .HasColumnType("int"); - b.Property("GuarantorId") .HasColumnType("int"); @@ -201,8 +203,6 @@ namespace ServiceStationDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("DefectId"); - b.HasIndex("GuarantorId"); b.ToTable("Repairs"); @@ -293,9 +293,6 @@ namespace ServiceStationDatabaseImplement.Migrations b.Property("ExecutorId") .HasColumnType("int"); - b.Property("WorkId") - .HasColumnType("int"); - b.Property("WorkPrice") .HasColumnType("float"); @@ -307,8 +304,6 @@ namespace ServiceStationDatabaseImplement.Migrations b.HasIndex("ExecutorId"); - b.HasIndex("WorkId"); - b.ToTable("TechnicalWorks"); }); @@ -326,6 +321,9 @@ namespace ServiceStationDatabaseImplement.Migrations b.Property("Status") .HasColumnType("int"); + b.Property("TechnicalWorkId") + .HasColumnType("int"); + b.Property("WorkName") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -337,6 +335,8 @@ namespace ServiceStationDatabaseImplement.Migrations b.HasIndex("GuarantorId"); + b.HasIndex("TechnicalWorkId"); + b.ToTable("Works"); }); @@ -397,23 +397,23 @@ namespace ServiceStationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ServiceStationDatabaseImplement.Models.Repair", "Repair") + .WithMany("Defects") + .HasForeignKey("RepairId"); + b.Navigation("Executor"); + + b.Navigation("Repair"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => { - b.HasOne("ServiceStationDatabaseImplement.Models.Defect", "Defect") - .WithMany("Repairs") - .HasForeignKey("DefectId"); - b.HasOne("ServiceStationDatabaseImplement.Models.Guarantor", "Guarantor") .WithMany("Repairs") .HasForeignKey("GuarantorId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("Defect"); - b.Navigation("Guarantor"); }); @@ -474,13 +474,7 @@ namespace ServiceStationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("ServiceStationDatabaseImplement.Models.Work", "Work") - .WithMany("TechnicalWorks") - .HasForeignKey("WorkId"); - b.Navigation("Executor"); - - b.Navigation("Work"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => @@ -491,7 +485,13 @@ namespace ServiceStationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ServiceStationDatabaseImplement.Models.TechnicalWork", "TechnicalWork") + .WithMany("Works") + .HasForeignKey("TechnicalWorkId"); + b.Navigation("Guarantor"); + + b.Navigation("TechnicalWork"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Car", b => @@ -504,8 +504,6 @@ namespace ServiceStationDatabaseImplement.Migrations modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b => { b.Navigation("Cars"); - - b.Navigation("Repairs"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Executor", b => @@ -528,6 +526,8 @@ namespace ServiceStationDatabaseImplement.Migrations modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => { + b.Navigation("Defects"); + b.Navigation("SpareParts"); }); @@ -541,13 +541,13 @@ namespace ServiceStationDatabaseImplement.Migrations modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b => { b.Navigation("Cars"); + + b.Navigation("Works"); }); modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => { b.Navigation("SpareParts"); - - b.Navigation("TechnicalWorks"); }); #pragma warning restore 612, 618 } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Models/Defect.cs b/ServiceStation/ServiceStationDatabaseImplement/Models/Defect.cs index b4a6509..63869b2 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Models/Defect.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Models/Defect.cs @@ -25,7 +25,10 @@ namespace ServiceStationDatabaseImplement.Models [Required] public int ExecutorId { get; set; } + public int? RepairId { get; set; } + public virtual Executor Executor { get; set; } + public virtual Repair? Repair { get; set; } private Dictionary? _defectCars = null; @@ -43,8 +46,6 @@ namespace ServiceStationDatabaseImplement.Models } [ForeignKey("DefectId")] public virtual List Cars { get; set; } = new(); - [ForeignKey("DefectId")] - public virtual List Repairs { get; set; } = new(); public static Defect? Create(ServiceStationDatabase context, DefectBindingModel model) { diff --git a/ServiceStation/ServiceStationDatabaseImplement/Models/Repair.cs b/ServiceStation/ServiceStationDatabaseImplement/Models/Repair.cs index 9d45b51..7a32411 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Models/Repair.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Models/Repair.cs @@ -28,13 +28,8 @@ namespace ServiceStationDatabaseImplement.Models [Required] public int GuarantorId { get; set; } - public int? DefectId { get; set; } - public virtual Guarantor Guarantor { get; set; } - public virtual Defect? Defect { get; set; } - - private Dictionary? _repairSpareParts = null; [NotMapped] @@ -52,6 +47,8 @@ namespace ServiceStationDatabaseImplement.Models [ForeignKey("RepairId")] public virtual List SpareParts { get; set; } = new(); + [ForeignKey("RepairId")] + public virtual List Defects { get; set; } = new(); public static Repair? Create(ServiceStationDatabase context, RepairBindingModel model) diff --git a/ServiceStation/ServiceStationDatabaseImplement/Models/TechnicalWork.cs b/ServiceStation/ServiceStationDatabaseImplement/Models/TechnicalWork.cs index 013acc7..ad7dd45 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Models/TechnicalWork.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Models/TechnicalWork.cs @@ -25,11 +25,8 @@ namespace ServiceStationDatabaseImplement.Models [Required] public int ExecutorId { get; set; } - public int? WorkId { get; set; } - public virtual Executor Executor { get; set; } - public virtual Work? Work { get; set; } private Dictionary? _technicalWorkCars = null; @@ -47,6 +44,8 @@ namespace ServiceStationDatabaseImplement.Models } [ForeignKey("TechnicalWorkId")] public virtual List Cars { get; set; } = new(); + [ForeignKey("TechnicalWorkId")] + public virtual List Works { get; set; } = new(); public static TechnicalWork? Create(ServiceStationDatabase context, TechnicalWorkBindingModel model) { @@ -78,7 +77,8 @@ namespace ServiceStationDatabaseImplement.Models WorkType = WorkType, DateStartWork = DateStartWork, WorkPrice = WorkPrice, - ExecutorId = ExecutorId + ExecutorId = ExecutorId, + TechnicalWorkCars = TechnicalWorkCars }; public void UpdateCars(ServiceStationDatabase context, TechnicalWorkBindingModel model) diff --git a/ServiceStation/ServiceStationDatabaseImplement/Models/Work.cs b/ServiceStation/ServiceStationDatabaseImplement/Models/Work.cs index 1cf926e..d339c7a 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Models/Work.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Models/Work.cs @@ -28,7 +28,10 @@ namespace ServiceStationDatabaseImplement.Models [Required] public int GuarantorId { get; set; } + public int? TechnicalWorkId { get; set; } + public virtual Guarantor Guarantor { get; set; } + public virtual TechnicalWork? TechnicalWork { get; set; } private Dictionary? _workSpareParts = null; @@ -48,9 +51,6 @@ namespace ServiceStationDatabaseImplement.Models [ForeignKey("WorkId")] public virtual List SpareParts { get; set; } = new(); - [ForeignKey("WorkId")] - public virtual List TechnicalWorks { get; set; } = new(); - public static Work? Create(ServiceStationDatabase context, WorkBindingModel model) { if (model == null) return null; @@ -70,6 +70,12 @@ namespace ServiceStationDatabaseImplement.Models public void Update(WorkBindingModel model) { + if(model == null) return; + if (model.TechnicalWorkId.HasValue) + { + TechnicalWorkId = model.TechnicalWorkId; + return; + } WorkName = model.WorkName; Status = model.Status; WorkPrice = model.WorkPrice; @@ -82,6 +88,8 @@ namespace ServiceStationDatabaseImplement.Models Status = Status, WorkPrice = WorkPrice, GuarantorId = GuarantorId, + TechnicalWorkId = TechnicalWorkId, + WorkSpareParts = WorkSpareParts, }; public void UpdateSpareParts(ServiceStationDatabase context, WorkBindingModel model)