From 3f55e0a50978f418517b58efc381ff2d1c8cad7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Sun, 2 Apr 2023 16:04:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9=20=D0=B8=20=D0=B1?= =?UTF-8?q?=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarService/CarService.sln | 6 + .../CarServiceDatabase.csproj | 27 ++ .../CarServiceDatabase/CarServiceDbContext.cs | 33 ++ .../20230402115927_InitMigration.Designer.cs | 386 ++++++++++++++++++ .../20230402115927_InitMigration.cs | 285 +++++++++++++ .../CarServiceDbContextModelSnapshot.cs | 383 +++++++++++++++++ .../CarServiceDatabase/Models/Customer.cs | 71 ++++ CarService/CarServiceDatabase/Models/Item.cs | 72 ++++ .../Models/ItemForRepair.cs | 60 +++ .../Models/RepairRequest.cs | 65 +++ .../CarServiceDatabase/Models/Vehicle.cs | 70 ++++ CarService/CarServiceDatabase/Models/Work.cs | 72 ++++ .../Models/WorkInRequest.cs | 72 ++++ .../CarServiceDatabase/Models/WorkPayment.cs | 62 +++ .../CarServiceDatabase/Models/Worker.cs | 76 ++++ .../CarServiceView/CarServiceView.csproj | 21 + CarService/CarServiceView/nlog.config | 14 + 17 files changed, 1775 insertions(+) create mode 100644 CarService/CarServiceDatabase/CarServiceDatabase.csproj create mode 100644 CarService/CarServiceDatabase/CarServiceDbContext.cs create mode 100644 CarService/CarServiceDatabase/Migrations/20230402115927_InitMigration.Designer.cs create mode 100644 CarService/CarServiceDatabase/Migrations/20230402115927_InitMigration.cs create mode 100644 CarService/CarServiceDatabase/Migrations/CarServiceDbContextModelSnapshot.cs create mode 100644 CarService/CarServiceDatabase/Models/Customer.cs create mode 100644 CarService/CarServiceDatabase/Models/Item.cs create mode 100644 CarService/CarServiceDatabase/Models/ItemForRepair.cs create mode 100644 CarService/CarServiceDatabase/Models/RepairRequest.cs create mode 100644 CarService/CarServiceDatabase/Models/Vehicle.cs create mode 100644 CarService/CarServiceDatabase/Models/Work.cs create mode 100644 CarService/CarServiceDatabase/Models/WorkInRequest.cs create mode 100644 CarService/CarServiceDatabase/Models/WorkPayment.cs create mode 100644 CarService/CarServiceDatabase/Models/Worker.cs create mode 100644 CarService/CarServiceView/nlog.config diff --git a/CarService/CarService.sln b/CarService/CarService.sln index 74555d5..b4cd2cb 100644 --- a/CarService/CarService.sln +++ b/CarService/CarService.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarServiceContracts", "CarS EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarServiceBusinessLogic", "CarServiceBusinessLogic\CarServiceBusinessLogic.csproj", "{F59A4E9C-1547-472A-ADE6-313D208430E1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarServiceDatabase", "CarServiceDatabase\CarServiceDatabase.csproj", "{1E57DD5F-5110-457C-8D9F-E34BBFE75A1F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {F59A4E9C-1547-472A-ADE6-313D208430E1}.Debug|Any CPU.Build.0 = Debug|Any CPU {F59A4E9C-1547-472A-ADE6-313D208430E1}.Release|Any CPU.ActiveCfg = Release|Any CPU {F59A4E9C-1547-472A-ADE6-313D208430E1}.Release|Any CPU.Build.0 = Release|Any CPU + {1E57DD5F-5110-457C-8D9F-E34BBFE75A1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E57DD5F-5110-457C-8D9F-E34BBFE75A1F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E57DD5F-5110-457C-8D9F-E34BBFE75A1F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E57DD5F-5110-457C-8D9F-E34BBFE75A1F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CarService/CarServiceDatabase/CarServiceDatabase.csproj b/CarService/CarServiceDatabase/CarServiceDatabase.csproj new file mode 100644 index 0000000..54ca861 --- /dev/null +++ b/CarService/CarServiceDatabase/CarServiceDatabase.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + diff --git a/CarService/CarServiceDatabase/CarServiceDbContext.cs b/CarService/CarServiceDatabase/CarServiceDbContext.cs new file mode 100644 index 0000000..ed81db4 --- /dev/null +++ b/CarService/CarServiceDatabase/CarServiceDbContext.cs @@ -0,0 +1,33 @@ +using CarServiceDatabase.Models; +using Microsoft.EntityFrameworkCore; + +namespace CarServiceDatabase +{ + public class CarServiceDbContext : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer + ( + @"Data Source=IGORS_2011; + Initial Catalog=CarServiceDatabase; + Integrated Security=True; + MultipleActiveResultSets=True; + TrustServerCertificate=True" + ); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Customers { get; set; } + public virtual DbSet Items { get; set; } + public virtual DbSet ItemsForRepair { get; set; } + public virtual DbSet RepairRequests { get; set; } + public virtual DbSet Vehicles { get; set; } + public virtual DbSet Works { get; set; } + public virtual DbSet Workers { get; set; } + public virtual DbSet WorksInRequest { get; set; } + public virtual DbSet WorkPayments { get; set; } + } +} diff --git a/CarService/CarServiceDatabase/Migrations/20230402115927_InitMigration.Designer.cs b/CarService/CarServiceDatabase/Migrations/20230402115927_InitMigration.Designer.cs new file mode 100644 index 0000000..dc298fd --- /dev/null +++ b/CarService/CarServiceDatabase/Migrations/20230402115927_InitMigration.Designer.cs @@ -0,0 +1,386 @@ +// +using System; +using CarServiceDatabase; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CarServiceDatabase.Migrations +{ + [DbContext(typeof(CarServiceDbContext))] + [Migration("20230402115927_InitMigration")] + partial class InitMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CarServiceDatabase.Models.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("Items"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.ItemForRepair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ItemId") + .HasColumnType("int"); + + b.Property("RepairRequestId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ItemId"); + + b.HasIndex("RepairRequestId"); + + b.ToTable("ItemsForRepair"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DateCreated") + .HasColumnType("datetime2"); + + b.Property("VehicleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("RepairRequests"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Plate") + .HasColumnType("nvarchar(max)"); + + b.Property("VIN") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("Vehicles"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Duration") + .HasColumnType("decimal (3,1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("Works"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("decimal (10,2)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("RepairRequestId") + .HasColumnType("int"); + + b.Property("WorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RepairRequestId"); + + b.HasIndex("WorkId"); + + b.ToTable("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkPayment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DatePayment") + .HasColumnType("datetime2"); + + b.Property("Sum") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkInRequestId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkInRequestId"); + + b.ToTable("WorkPayments"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Worker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Workers"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.HasOne("CarServiceDatabase.Models.Worker", null) + .WithMany("Items") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.ItemForRepair", b => + { + b.HasOne("CarServiceDatabase.Models.Item", null) + .WithMany("ItemsForRepair") + .HasForeignKey("ItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarServiceDatabase.Models.RepairRequest", null) + .WithMany("ItemsForRepair") + .HasForeignKey("RepairRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.HasOne("CarServiceDatabase.Models.Vehicle", null) + .WithMany("RepairRequests") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.HasOne("CarServiceDatabase.Models.Customer", null) + .WithMany("Vehicles") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.HasOne("CarServiceDatabase.Models.Worker", null) + .WithMany("Works") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.HasOne("CarServiceDatabase.Models.RepairRequest", null) + .WithMany("WorksInRequest") + .HasForeignKey("RepairRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarServiceDatabase.Models.Work", null) + .WithMany("WorksInRequest") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkPayment", b => + { + b.HasOne("CarServiceDatabase.Models.WorkInRequest", null) + .WithMany("WorkPayments") + .HasForeignKey("WorkInRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Customer", b => + { + b.Navigation("Vehicles"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.Navigation("ItemsForRepair"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.Navigation("ItemsForRepair"); + + b.Navigation("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.Navigation("RepairRequests"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.Navigation("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.Navigation("WorkPayments"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Worker", b => + { + b.Navigation("Items"); + + b.Navigation("Works"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CarService/CarServiceDatabase/Migrations/20230402115927_InitMigration.cs b/CarService/CarServiceDatabase/Migrations/20230402115927_InitMigration.cs new file mode 100644 index 0000000..3f5cb9c --- /dev/null +++ b/CarService/CarServiceDatabase/Migrations/20230402115927_InitMigration.cs @@ -0,0 +1,285 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CarServiceDatabase.Migrations +{ + /// + public partial class InitMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Customers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Login = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Surname = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Customers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Workers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Login = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Surname = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Workers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Vehicles", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Plate = table.Column(type: "nvarchar(max)", nullable: true), + VIN = table.Column(type: "nvarchar(max)", nullable: true), + CustomerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Vehicles", x => x.Id); + table.ForeignKey( + name: "FK_Vehicles_Customers_CustomerId", + column: x => x.CustomerId, + principalTable: "Customers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Items", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "decimal (10,2)", nullable: false), + Count = table.Column(type: "int", nullable: false), + WorkerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Items", x => x.Id); + table.ForeignKey( + name: "FK_Items_Workers_WorkerId", + column: x => x.WorkerId, + principalTable: "Workers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Works", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "decimal (10,2)", nullable: false), + Duration = table.Column(type: "decimal (3,1)", nullable: false), + WorkerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Works", x => x.Id); + table.ForeignKey( + name: "FK_Works_Workers_WorkerId", + column: x => x.WorkerId, + principalTable: "Workers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "RepairRequests", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DateCreated = table.Column(type: "datetime2", nullable: false), + VehicleId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RepairRequests", x => x.Id); + table.ForeignKey( + name: "FK_RepairRequests_Vehicles_VehicleId", + column: x => x.VehicleId, + principalTable: "Vehicles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ItemsForRepair", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Count = table.Column(type: "int", nullable: false), + ItemId = table.Column(type: "int", nullable: false), + RepairRequestId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ItemsForRepair", x => x.Id); + table.ForeignKey( + name: "FK_ItemsForRepair_Items_ItemId", + column: x => x.ItemId, + principalTable: "Items", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ItemsForRepair_RepairRequests_RepairRequestId", + column: x => x.RepairRequestId, + principalTable: "RepairRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "WorksInRequest", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Count = table.Column(type: "int", nullable: false), + Cost = table.Column(type: "decimal (10,2)", nullable: false), + RepairRequestId = table.Column(type: "int", nullable: false), + WorkId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WorksInRequest", x => x.Id); + table.ForeignKey( + name: "FK_WorksInRequest_RepairRequests_RepairRequestId", + column: x => x.RepairRequestId, + principalTable: "RepairRequests", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_WorksInRequest_Works_WorkId", + column: x => x.WorkId, + principalTable: "Works", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "WorkPayments", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DatePayment = table.Column(type: "datetime2", nullable: false), + Sum = table.Column(type: "decimal (10,2)", nullable: false), + WorkInRequestId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WorkPayments", x => x.Id); + table.ForeignKey( + name: "FK_WorkPayments_WorksInRequest_WorkInRequestId", + column: x => x.WorkInRequestId, + principalTable: "WorksInRequest", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Items_WorkerId", + table: "Items", + column: "WorkerId"); + + migrationBuilder.CreateIndex( + name: "IX_ItemsForRepair_ItemId", + table: "ItemsForRepair", + column: "ItemId"); + + migrationBuilder.CreateIndex( + name: "IX_ItemsForRepair_RepairRequestId", + table: "ItemsForRepair", + column: "RepairRequestId"); + + migrationBuilder.CreateIndex( + name: "IX_RepairRequests_VehicleId", + table: "RepairRequests", + column: "VehicleId"); + + migrationBuilder.CreateIndex( + name: "IX_Vehicles_CustomerId", + table: "Vehicles", + column: "CustomerId"); + + migrationBuilder.CreateIndex( + name: "IX_WorkPayments_WorkInRequestId", + table: "WorkPayments", + column: "WorkInRequestId"); + + migrationBuilder.CreateIndex( + name: "IX_Works_WorkerId", + table: "Works", + column: "WorkerId"); + + migrationBuilder.CreateIndex( + name: "IX_WorksInRequest_RepairRequestId", + table: "WorksInRequest", + column: "RepairRequestId"); + + migrationBuilder.CreateIndex( + name: "IX_WorksInRequest_WorkId", + table: "WorksInRequest", + column: "WorkId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ItemsForRepair"); + + migrationBuilder.DropTable( + name: "WorkPayments"); + + migrationBuilder.DropTable( + name: "Items"); + + migrationBuilder.DropTable( + name: "WorksInRequest"); + + migrationBuilder.DropTable( + name: "RepairRequests"); + + migrationBuilder.DropTable( + name: "Works"); + + migrationBuilder.DropTable( + name: "Vehicles"); + + migrationBuilder.DropTable( + name: "Workers"); + + migrationBuilder.DropTable( + name: "Customers"); + } + } +} diff --git a/CarService/CarServiceDatabase/Migrations/CarServiceDbContextModelSnapshot.cs b/CarService/CarServiceDatabase/Migrations/CarServiceDbContextModelSnapshot.cs new file mode 100644 index 0000000..eb61091 --- /dev/null +++ b/CarService/CarServiceDatabase/Migrations/CarServiceDbContextModelSnapshot.cs @@ -0,0 +1,383 @@ +// +using System; +using CarServiceDatabase; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CarServiceDatabase.Migrations +{ + [DbContext(typeof(CarServiceDbContext))] + partial class CarServiceDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CarServiceDatabase.Models.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("Items"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.ItemForRepair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ItemId") + .HasColumnType("int"); + + b.Property("RepairRequestId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ItemId"); + + b.HasIndex("RepairRequestId"); + + b.ToTable("ItemsForRepair"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DateCreated") + .HasColumnType("datetime2"); + + b.Property("VehicleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("RepairRequests"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Plate") + .HasColumnType("nvarchar(max)"); + + b.Property("VIN") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("Vehicles"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Duration") + .HasColumnType("decimal (3,1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("Works"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("decimal (10,2)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("RepairRequestId") + .HasColumnType("int"); + + b.Property("WorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RepairRequestId"); + + b.HasIndex("WorkId"); + + b.ToTable("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkPayment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DatePayment") + .HasColumnType("datetime2"); + + b.Property("Sum") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkInRequestId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkInRequestId"); + + b.ToTable("WorkPayments"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Worker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Workers"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.HasOne("CarServiceDatabase.Models.Worker", null) + .WithMany("Items") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.ItemForRepair", b => + { + b.HasOne("CarServiceDatabase.Models.Item", null) + .WithMany("ItemsForRepair") + .HasForeignKey("ItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarServiceDatabase.Models.RepairRequest", null) + .WithMany("ItemsForRepair") + .HasForeignKey("RepairRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.HasOne("CarServiceDatabase.Models.Vehicle", null) + .WithMany("RepairRequests") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.HasOne("CarServiceDatabase.Models.Customer", null) + .WithMany("Vehicles") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.HasOne("CarServiceDatabase.Models.Worker", null) + .WithMany("Works") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.HasOne("CarServiceDatabase.Models.RepairRequest", null) + .WithMany("WorksInRequest") + .HasForeignKey("RepairRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarServiceDatabase.Models.Work", null) + .WithMany("WorksInRequest") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkPayment", b => + { + b.HasOne("CarServiceDatabase.Models.WorkInRequest", null) + .WithMany("WorkPayments") + .HasForeignKey("WorkInRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Customer", b => + { + b.Navigation("Vehicles"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.Navigation("ItemsForRepair"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.Navigation("ItemsForRepair"); + + b.Navigation("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.Navigation("RepairRequests"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.Navigation("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.Navigation("WorkPayments"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Worker", b => + { + b.Navigation("Items"); + + b.Navigation("Works"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CarService/CarServiceDatabase/Models/Customer.cs b/CarService/CarServiceDatabase/Models/Customer.cs new file mode 100644 index 0000000..07f0ea7 --- /dev/null +++ b/CarService/CarServiceDatabase/Models/Customer.cs @@ -0,0 +1,71 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace CarServiceDatabase.Models +{ + public class Customer : ICustomerModel + { + public int Id { get; private set; } + [Required] + public string Login { get; private set; } = string.Empty; + [Required] + public string Password { get; private set; } = string.Empty; + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + public string Surname { get; private set; } = string.Empty; + /// + /// Транспортные средства + /// + [ForeignKey("CustomerId")] + public virtual List Vehicles { get; set; } = new(); + public static Customer? Create(CustomerBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Name = model.Name, + Surname = model.Surname + }; + } + public static Customer Create(CustomerViewModel model) + { + return new() + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Name = model.Name, + Surname = model.Surname + }; + } + public void Update(CustomerBindingModel? model) + { + if (model == null) + { + return; + } + Login = model.Login; + Password = model.Password; + Name = model.Name; + Surname = model.Surname; + } + public CustomerViewModel GetViewModel => new() + { + Id = Id, + Login = Login, + Password = Password, + Name = Name, + Surname = Surname + }; + } +} diff --git a/CarService/CarServiceDatabase/Models/Item.cs b/CarService/CarServiceDatabase/Models/Item.cs new file mode 100644 index 0000000..4108142 --- /dev/null +++ b/CarService/CarServiceDatabase/Models/Item.cs @@ -0,0 +1,72 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace CarServiceDatabase.Models +{ + public class Item : IItemModel + { + public int Id { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required, Column(TypeName = "decimal (10,2)")] + public decimal Price { get; private set; } + [Required] + public int Count { get; private set; } + [Required] + public int WorkerId { get; private set; } + /// + /// Затраты на ремонт + /// + [ForeignKey("ItemId")] + public virtual List ItemsForRepair { get; set; } = new(); + public static Item? Create(ItemBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Name = model.Name, + Price = model.Price, + Count = model.Count, + WorkerId = model.WorkerId + }; + } + public static Item Create(ItemViewModel model) + { + return new() + { + Id = model.Id, + Name = model.Name, + Price = model.Price, + Count = model.Count, + WorkerId = model.WorkerId + }; + } + public void Update(ItemBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + Name = model.Name; + Price = model.Price; + Count = model.Count; + WorkerId = model.WorkerId; + } + public ItemViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Price = Price, + Count = Count, + WorkerId = WorkerId + }; + } +} diff --git a/CarService/CarServiceDatabase/Models/ItemForRepair.cs b/CarService/CarServiceDatabase/Models/ItemForRepair.cs new file mode 100644 index 0000000..7c6ba03 --- /dev/null +++ b/CarService/CarServiceDatabase/Models/ItemForRepair.cs @@ -0,0 +1,60 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using System.ComponentModel.DataAnnotations; + +namespace CarServiceDatabase.Models +{ + public class ItemForRepair : IItemForRepairModel + { + public int Id { get; private set; } + [Required] + public int Count { get; private set; } + [Required] + public int ItemId { get; private set; } + [Required] + public int RepairRequestId { get; private set; } + public static ItemForRepair? Create(ItemForRepairBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Count = model.Count, + ItemId = model.ItemId, + RepairRequestId = model.RepairRequestId + }; + } + public static ItemForRepair Create(ItemForRepairViewModel model) + { + return new() + { + Id = model.Id, + Count = model.Count, + ItemId = model.ItemId, + RepairRequestId = model.RepairRequestId + }; + } + public void Update(ItemForRepairBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + Count = model.Count; + ItemId = model.ItemId; + RepairRequestId = model.RepairRequestId; + } + public ItemForRepairViewModel GetViewModel => new() + { + Id = Id, + Count = Count, + ItemId = ItemId, + RepairRequestId = RepairRequestId + }; + } +} diff --git a/CarService/CarServiceDatabase/Models/RepairRequest.cs b/CarService/CarServiceDatabase/Models/RepairRequest.cs new file mode 100644 index 0000000..8b441be --- /dev/null +++ b/CarService/CarServiceDatabase/Models/RepairRequest.cs @@ -0,0 +1,65 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace CarServiceDatabase.Models +{ + public class RepairRequest : IRepairRequestModel + { + public int Id { get; private set; } + [Required] + public DateTime DateCreated { get; private set; } = DateTime.Now; + [Required] + public int VehicleId { get; private set; } + /// + /// Работы в заявке + /// + [ForeignKey("RepairRequestId")] + public virtual List WorksInRequest { get; set; } = new(); + /// + /// Затраты на ремонт + /// + [ForeignKey("RepairRequestId")] + public virtual List ItemsForRepair { get; set; } = new(); + public static RepairRequest? Create(RepairRequestBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + DateCreated = model.DateCreated, + VehicleId = model.VehicleId + }; + } + public static RepairRequest Create(RepairRequestViewModel model) + { + return new() + { + Id = model.Id, + DateCreated = model.DateCreated, + VehicleId = model.VehicleId + }; + } + public void Update(RepairRequestBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + DateCreated = model.DateCreated; + VehicleId = model.VehicleId; + } + public RepairRequestViewModel GetViewModel => new() + { + Id = Id, + DateCreated = DateCreated, + VehicleId = VehicleId + }; + } +} diff --git a/CarService/CarServiceDatabase/Models/Vehicle.cs b/CarService/CarServiceDatabase/Models/Vehicle.cs new file mode 100644 index 0000000..099c02a --- /dev/null +++ b/CarService/CarServiceDatabase/Models/Vehicle.cs @@ -0,0 +1,70 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace CarServiceDatabase.Models +{ + public class Vehicle : IVehicleModel + { + public int Id { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + public string? Plate { get; private set; } + public string? VIN { get; private set; } + [Required] + public int CustomerId { get; private set; } + /// + /// Заявки на ремонт + /// + [ForeignKey("VehicleId")] + public virtual List RepairRequests { get; set; } = new(); + public static Vehicle? Create(VehicleBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Name = model.Name, + Plate = model.Plate, + VIN = model.VIN, + CustomerId = model.CustomerId + }; + } + public static Vehicle Create(VehicleViewModel model) + { + return new() + { + Id = model.Id, + Name = model.Name, + Plate = model.Plate, + VIN = model.VIN, + CustomerId = model.CustomerId + }; + } + public void Update(VehicleBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + Name = model.Name; + Plate = model.Plate; + VIN = model.VIN; + CustomerId = model.CustomerId; + } + public VehicleViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Plate = Plate, + VIN = VIN, + CustomerId = CustomerId + }; + } +} diff --git a/CarService/CarServiceDatabase/Models/Work.cs b/CarService/CarServiceDatabase/Models/Work.cs new file mode 100644 index 0000000..0e2966e --- /dev/null +++ b/CarService/CarServiceDatabase/Models/Work.cs @@ -0,0 +1,72 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace CarServiceDatabase.Models +{ + public class Work : IWorkModel + { + public int Id { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required, Column(TypeName = "decimal (10,2)")] + public decimal Price { get; private set; } + [Required, Column(TypeName = "decimal (3,1)")] + public decimal Duration { get; private set; } + [Required] + public int WorkerId { get; private set; } + /// + /// Работы в заявке + /// + [ForeignKey("WorkId")] + public virtual List WorksInRequest { get; set; } = new(); + public static Work? Create(WorkBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Name = model.Name, + Price = model.Price, + Duration = model.Duration, + WorkerId = model.WorkerId + }; + } + public static Work Create(WorkViewModel model) + { + return new() + { + Id = model.Id, + Name = model.Name, + Price = model.Price, + Duration = model.Duration, + WorkerId = model.WorkerId + }; + } + public void Update(WorkBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + Name = model.Name; + Price = model.Price; + Duration = model.Duration; + WorkerId = model.WorkerId; + } + public WorkViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Price = Price, + Duration = Duration, + WorkerId = WorkerId + }; + } +} diff --git a/CarService/CarServiceDatabase/Models/WorkInRequest.cs b/CarService/CarServiceDatabase/Models/WorkInRequest.cs new file mode 100644 index 0000000..9fb830a --- /dev/null +++ b/CarService/CarServiceDatabase/Models/WorkInRequest.cs @@ -0,0 +1,72 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace CarServiceDatabase.Models +{ + public class WorkInRequest : IWorkInRequestModel + { + public int Id { get; private set; } + [Required] + public int Count { get; private set; } + [Required, Column(TypeName = "decimal (10,2)")] + public decimal Cost { get; private set; } + [Required] + public int RepairRequestId { get; private set; } + [Required] + public int WorkId { get; private set; } + /// + /// Оплаты за ремонт + /// + [ForeignKey("WorkInRequestId")] + public virtual List WorkPayments { get; set; } = new(); + public static WorkInRequest? Create(WorkInRequestBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Count = model.Count, + Cost = model.Cost, + RepairRequestId = model.RepairRequestId, + WorkId = model.WorkId + }; + } + public static WorkInRequest Create(WorkInRequestViewModel model) + { + return new() + { + Id = model.Id, + Count = model.Count, + Cost = model.Cost, + RepairRequestId = model.RepairRequestId, + WorkId = model.WorkId + }; + } + public void Update(WorkInRequestBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + Count = model.Count; + Cost = model.Cost; + RepairRequestId = model.RepairRequestId; + WorkId = model.WorkId; + } + public WorkInRequestViewModel GetViewModel => new() + { + Id = Id, + Count = Count, + Cost = Cost, + RepairRequestId = RepairRequestId, + WorkId = WorkId + }; + } +} diff --git a/CarService/CarServiceDatabase/Models/WorkPayment.cs b/CarService/CarServiceDatabase/Models/WorkPayment.cs new file mode 100644 index 0000000..b4b6a80 --- /dev/null +++ b/CarService/CarServiceDatabase/Models/WorkPayment.cs @@ -0,0 +1,62 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace CarServiceDatabase.Models +{ + public class WorkPayment : IWorkPaymentModel + { + public int Id { get; private set; } + [Required] + public DateTime DatePayment { get; private set; } = DateTime.Now; + [Required, Column(TypeName = "decimal (10,2)")] + public decimal Sum { get; private set; } + [Required] + public int WorkInRequestId { get; private set; } + public static WorkPayment? Create(WorkPaymentBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + DatePayment = model.DatePayment, + Sum = model.Sum, + WorkInRequestId = model.WorkInRequestId + }; + } + public static WorkPayment Create(WorkPaymentViewModel model) + { + return new() + { + Id = model.Id, + DatePayment = model.DatePayment, + Sum = model.Sum, + WorkInRequestId = model.WorkInRequestId + }; + } + public void Update(WorkPaymentBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + DatePayment = model.DatePayment; + Sum = model.Sum; + WorkInRequestId = model.WorkInRequestId; + } + public WorkPaymentViewModel GetViewModel => new() + { + Id = Id, + DatePayment = DatePayment, + Sum = Sum, + WorkInRequestId = WorkInRequestId + }; + } +} diff --git a/CarService/CarServiceDatabase/Models/Worker.cs b/CarService/CarServiceDatabase/Models/Worker.cs new file mode 100644 index 0000000..17945c8 --- /dev/null +++ b/CarService/CarServiceDatabase/Models/Worker.cs @@ -0,0 +1,76 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.Models; +using CarServiceContracts.ViewModels; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace CarServiceDatabase.Models +{ + public class Worker : IWorkerModel + { + public int Id { get; private set; } + [Required] + public string Login { get; private set; } = string.Empty; + [Required] + public string Password { get; private set; } = string.Empty; + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + public string Surname { get; private set; } = string.Empty; + /// + /// Работы + /// + [ForeignKey("WorkerId")] + public virtual List Works { get; set; } = new(); + /// + /// Статьи затрат + /// + [ForeignKey("WorkerId")] + public virtual List Items { get; set; } = new(); + public static Worker? Create(WorkerBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Name = model.Name, + Surname = model.Surname + }; + } + public static Worker Create(WorkerViewModel model) + { + return new() + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Name = model.Name, + Surname = model.Surname + }; + } + public void Update(WorkerBindingModel? model) + { + if (model == null) + { + return; + } + Login = model.Login; + Password = model.Password; + Name = model.Name; + Surname = model.Surname; + } + public WorkerViewModel GetViewModel => new() + { + Id = Id, + Login = Login, + Password = Password, + Name = Name, + Surname = Surname + }; + } +} diff --git a/CarService/CarServiceView/CarServiceView.csproj b/CarService/CarServiceView/CarServiceView.csproj index b57c89e..085bb98 100644 --- a/CarService/CarServiceView/CarServiceView.csproj +++ b/CarService/CarServiceView/CarServiceView.csproj @@ -8,4 +8,25 @@ enable + + + + + + + PreserveNewest + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + \ No newline at end of file diff --git a/CarService/CarServiceView/nlog.config b/CarService/CarServiceView/nlog.config new file mode 100644 index 0000000..0ddb3aa --- /dev/null +++ b/CarService/CarServiceView/nlog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file