diff --git a/ServiceStation/ServiceStationContracts/BindingModels/RepairBindingModel.cs b/ServiceStation/ServiceStationContracts/BindingModels/RepairBindingModel.cs index 1210e9c..98c0632 100644 --- a/ServiceStation/ServiceStationContracts/BindingModels/RepairBindingModel.cs +++ b/ServiceStation/ServiceStationContracts/BindingModels/RepairBindingModel.cs @@ -14,7 +14,7 @@ namespace ServiceStationContracts.BindingModels public string RepairName { get; set; } = string.Empty; - public RepairStatus Status { get; set; } = RepairStatus.Неизвестен; + public DateTime? RepairStartDate { get; set; } = DateTime.Now; public double RepairPrice { get; set; } diff --git a/ServiceStation/ServiceStationContracts/SearchModels/RepairSearchModel.cs b/ServiceStation/ServiceStationContracts/SearchModels/RepairSearchModel.cs index 8452841..40d327b 100644 --- a/ServiceStation/ServiceStationContracts/SearchModels/RepairSearchModel.cs +++ b/ServiceStation/ServiceStationContracts/SearchModels/RepairSearchModel.cs @@ -12,5 +12,7 @@ namespace ServiceStationContracts.SearchModels public string? RepairName { get; set; } public int? GuarantorId { get; set; } public int? DefectId { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/ServiceStation/ServiceStationContracts/ViewModels/RepairViewModel.cs b/ServiceStation/ServiceStationContracts/ViewModels/RepairViewModel.cs index 39bd06d..7201a2a 100644 --- a/ServiceStation/ServiceStationContracts/ViewModels/RepairViewModel.cs +++ b/ServiceStation/ServiceStationContracts/ViewModels/RepairViewModel.cs @@ -16,8 +16,8 @@ namespace ServiceStationContracts.ViewModels [DisplayName("Наименование ремонта")] public string RepairName { get; set; } = string.Empty; - [DisplayName("Статус ремонта")] - public RepairStatus Status { get; set; } + [DisplayName("Начало ремонта")] + public DateTime? RepairStartDate { get; set; } = DateTime.Now; [DisplayName("Стоимость ремонта")] public double RepairPrice { get; set; } diff --git a/ServiceStation/ServiceStationDataModels/Models/IRepairModel.cs b/ServiceStation/ServiceStationDataModels/Models/IRepairModel.cs index fba182b..d67e9dc 100644 --- a/ServiceStation/ServiceStationDataModels/Models/IRepairModel.cs +++ b/ServiceStation/ServiceStationDataModels/Models/IRepairModel.cs @@ -10,7 +10,7 @@ namespace ServiceStationDataModels.Models { string RepairName { get; } - Enums.RepairStatus Status { get; } + DateTime? RepairStartDate { get; } double RepairPrice { get; } diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs index a0db03a..8ca56e6 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs @@ -29,9 +29,23 @@ namespace ServiceStationDatabaseImplement.Implements public List GetFilteredList(RepairSearchModel model) { - if (string.IsNullOrEmpty(model.RepairName) && !model.GuarantorId.HasValue) return new(); + if (string.IsNullOrEmpty(model.RepairName) && !model.GuarantorId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) return new(); using var context = new ServiceStationDatabase(); + if(model.DateTo.HasValue && model.DateTo.HasValue && model.GuarantorId.HasValue) + { + return context.Repairs + .Include(x => x.SpareParts) + .ThenInclude(x => x.SparePart) + .ThenInclude(x => x.SparePartWorks) + .ThenInclude(x => x.Work) + .Include(x => x.Guarantor) + .Where(x => x.RepairStartDate >= model.DateFrom && x.RepairStartDate <= model.DateTo && x.GuarantorId == model.GuarantorId) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.GuarantorId.HasValue) { return context.Repairs diff --git a/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240430202710_CorrectionMigration.Designer.cs b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240430202710_CorrectionMigration.Designer.cs new file mode 100644 index 0000000..d23cf9c --- /dev/null +++ b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240430202710_CorrectionMigration.Designer.cs @@ -0,0 +1,558 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ServiceStationDatabaseImplement; + +#nullable disable + +namespace ServiceStationDatabaseImplement.Migrations +{ + [DbContext(typeof(ServiceStationDatabase))] + [Migration("20240430202710_CorrectionMigration")] + partial class CorrectionMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Car", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarBrand") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CarNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.ToTable("Cars"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.CarDefect", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("DefectId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("DefectId"); + + b.ToTable("CarDefects"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.CarTechnicalWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("TechnicalWorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("TechnicalWorkId"); + + b.ToTable("CarTechnicalWorks"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DefectPrice") + .HasColumnType("float"); + + b.Property("DefectType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("RepairId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.HasIndex("RepairId"); + + b.ToTable("Defects"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Executor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ExecutorEmail") + .HasColumnType("nvarchar(max)"); + + b.Property("ExecutorFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExecutorNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExecutorPassword") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Executors"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Guarantor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("GuarantorEmail") + .HasColumnType("nvarchar(max)"); + + b.Property("GuarantorFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("GuarantorNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("GuarantorPassword") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Guarantors"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("RepairName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("RepairPrice") + .HasColumnType("float"); + + b.Property("RepairStartDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Repairs"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("SparePartName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SparePartPrice") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.ToTable("SpareParts"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartRepair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("RepairId") + .HasColumnType("int"); + + b.Property("SparePartId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RepairId"); + + b.HasIndex("SparePartId"); + + b.ToTable("SparePartRepairs"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("SparePartId") + .HasColumnType("int"); + + b.Property("WorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("SparePartId"); + + b.HasIndex("WorkId"); + + b.ToTable("SparePartWorks"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DateStartWork") + .HasColumnType("datetime2"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("WorkPrice") + .HasColumnType("float"); + + b.Property("WorkType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.ToTable("TechnicalWorks"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("TechnicalWorkId") + .HasColumnType("int"); + + b.Property("WorkName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("WorkPrice") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.HasIndex("TechnicalWorkId"); + + b.ToTable("Works"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Car", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.Executor", "Executor") + .WithMany("Cars") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Executor"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.CarDefect", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.Car", "Car") + .WithMany("CarDefects") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ServiceStationDatabaseImplement.Models.Defect", "Defect") + .WithMany("Cars") + .HasForeignKey("DefectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("Defect"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.CarTechnicalWork", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.Car", "Car") + .WithMany("CarTechnicalWorks") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ServiceStationDatabaseImplement.Models.TechnicalWork", "TechnicalWork") + .WithMany("Cars") + .HasForeignKey("TechnicalWorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("TechnicalWork"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.Executor", "Executor") + .WithMany("Defects") + .HasForeignKey("ExecutorId") + .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.Guarantor", "Guarantor") + .WithMany("Repairs") + .HasForeignKey("GuarantorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Guarantor"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePart", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.Guarantor", "Guarantor") + .WithMany("SpareParts") + .HasForeignKey("GuarantorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Guarantor"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartRepair", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.Repair", "Repair") + .WithMany("SpareParts") + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ServiceStationDatabaseImplement.Models.SparePart", "SparePart") + .WithMany("SparePartRepairs") + .HasForeignKey("SparePartId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Repair"); + + b.Navigation("SparePart"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePartWork", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.SparePart", "SparePart") + .WithMany("SparePartWorks") + .HasForeignKey("SparePartId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ServiceStationDatabaseImplement.Models.Work", "Work") + .WithMany("SpareParts") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SparePart"); + + b.Navigation("Work"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.Executor", "Executor") + .WithMany("TechnicalWorks") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Executor"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => + { + b.HasOne("ServiceStationDatabaseImplement.Models.Guarantor", "Guarantor") + .WithMany("Works") + .HasForeignKey("GuarantorId") + .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 => + { + b.Navigation("CarDefects"); + + b.Navigation("CarTechnicalWorks"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b => + { + b.Navigation("Cars"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Executor", b => + { + b.Navigation("Cars"); + + b.Navigation("Defects"); + + b.Navigation("TechnicalWorks"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Guarantor", b => + { + b.Navigation("Repairs"); + + b.Navigation("SpareParts"); + + b.Navigation("Works"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => + { + b.Navigation("Defects"); + + b.Navigation("SpareParts"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.SparePart", b => + { + b.Navigation("SparePartRepairs"); + + b.Navigation("SparePartWorks"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b => + { + b.Navigation("Cars"); + + b.Navigation("Works"); + }); + + modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => + { + b.Navigation("SpareParts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240430202710_CorrectionMigration.cs b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240430202710_CorrectionMigration.cs new file mode 100644 index 0000000..2159b0e --- /dev/null +++ b/ServiceStation/ServiceStationDatabaseImplement/Migrations/20240430202710_CorrectionMigration.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ServiceStationDatabaseImplement.Migrations +{ + /// + public partial class CorrectionMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Status", + table: "Repairs"); + + migrationBuilder.AddColumn( + name: "RepairStartDate", + table: "Repairs", + type: "datetime2", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "RepairStartDate", + table: "Repairs"); + + migrationBuilder.AddColumn( + name: "Status", + table: "Repairs", + type: "int", + nullable: false, + defaultValue: 0); + } + } +} diff --git a/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs b/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs index 60d8c1b..6191025 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Migrations/ServiceStationDatabaseModelSnapshot.cs @@ -198,8 +198,8 @@ namespace ServiceStationDatabaseImplement.Migrations b.Property("RepairPrice") .HasColumnType("float"); - b.Property("Status") - .HasColumnType("int"); + b.Property("RepairStartDate") + .HasColumnType("datetime2"); b.HasKey("Id"); diff --git a/ServiceStation/ServiceStationDatabaseImplement/Models/Repair.cs b/ServiceStation/ServiceStationDatabaseImplement/Models/Repair.cs index 7a32411..e24400b 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Models/Repair.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Models/Repair.cs @@ -19,8 +19,7 @@ namespace ServiceStationDatabaseImplement.Models [Required] public string RepairName { get; set; } = string.Empty; - [Required] - public RepairStatus Status { get; set; } + public DateTime? RepairStartDate { get; set; } = DateTime.Now; [Required] public double RepairPrice { get; set; } @@ -58,7 +57,7 @@ namespace ServiceStationDatabaseImplement.Models { Id = model.Id, RepairName = model.RepairName, - Status = model.Status, + RepairStartDate = model.RepairStartDate, RepairPrice = model.RepairPrice, GuarantorId = model.GuarantorId, SpareParts = model.RepairSpareParts.Select(x => new SparePartRepair @@ -72,7 +71,7 @@ namespace ServiceStationDatabaseImplement.Models { if (model == null) return; RepairName = model.RepairName; - Status = model.Status; + RepairStartDate = model.RepairStartDate; RepairPrice = model.RepairPrice; } @@ -80,7 +79,7 @@ namespace ServiceStationDatabaseImplement.Models { Id = Id, RepairName = RepairName, - Status = Status, + RepairStartDate = RepairStartDate, RepairPrice = RepairPrice, GuarantorId = GuarantorId, RepairSpareParts = RepairSpareParts