From 7e61baddbf5a7b1ef636eb34513ddd5374de6e28 Mon Sep 17 00:00:00 2001 From: sardq Date: Fri, 17 May 2024 15:20:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... => 20240517111715_InitCreate.Designer.cs} | 15 +++++- ...Create.cs => 20240517111715_InitCreate.cs} | 46 +++++++++++-------- .../PlumbingRepairDatabaseModelSnapshot.cs | 13 ++++++ .../Models/Client.cs | 5 +- .../Models/MessageInfo.cs | 2 + 5 files changed, 60 insertions(+), 21 deletions(-) rename PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/{20240515153909_InitCreate.Designer.cs => 20240517111715_InitCreate.Designer.cs} (96%) rename PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/{20240515153909_InitCreate.cs => 20240517111715_InitCreate.cs} (96%) diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240515153909_InitCreate.Designer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240517111715_InitCreate.Designer.cs similarity index 96% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240515153909_InitCreate.Designer.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240517111715_InitCreate.Designer.cs index 701adcf..3c5618c 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240515153909_InitCreate.Designer.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240517111715_InitCreate.Designer.cs @@ -12,7 +12,7 @@ using PlumbingRepairDatabaseImplement; namespace PlumbingRepairDatabaseImplement.Migrations { [DbContext(typeof(PlumbingRepairDatabase))] - [Migration("20240515153909_InitCreate")] + [Migration("20240517111715_InitCreate")] partial class InitCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -127,6 +127,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.HasKey("MessageId"); + b.HasIndex("ClientId"); + b.ToTable("Messages"); }); @@ -272,6 +274,15 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.ToTable("WorkComponents"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b => { b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client") @@ -337,6 +348,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240515153909_InitCreate.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240517111715_InitCreate.cs similarity index 96% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240515153909_InitCreate.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240517111715_InitCreate.cs index 0037ed3..76d58f1 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240515153909_InitCreate.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240517111715_InitCreate.cs @@ -54,24 +54,6 @@ namespace PlumbingRepairDatabaseImplement.Migrations table.PrimaryKey("PK_Implementers", x => x.Id); }); - migrationBuilder.CreateTable( - name: "Messages", - columns: table => new - { - MessageId = table.Column(type: "nvarchar(450)", nullable: false), - ClientId = table.Column(type: "int", nullable: true), - SenderName = table.Column(type: "nvarchar(max)", nullable: false), - DateDelivery = table.Column(type: "datetime2", nullable: false), - Subject = table.Column(type: "nvarchar(max)", nullable: false), - Body = table.Column(type: "nvarchar(max)", nullable: false), - IsRead = table.Column(type: "bit", nullable: false), - ReplyText = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Messages", x => x.MessageId); - }); - migrationBuilder.CreateTable( name: "Shops", columns: table => new @@ -102,6 +84,29 @@ namespace PlumbingRepairDatabaseImplement.Migrations table.PrimaryKey("PK_Works", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false), + IsRead = table.Column(type: "bit", nullable: false), + ReplyText = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageId); + table.ForeignKey( + name: "FK_Messages_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -193,6 +198,11 @@ namespace PlumbingRepairDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientId", + table: "Messages", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ClientId", table: "Orders", diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs index 122b902..408f110 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs @@ -125,6 +125,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.HasKey("MessageId"); + b.HasIndex("ClientId"); + b.ToTable("Messages"); }); @@ -270,6 +272,15 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.ToTable("WorkComponents"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b => { b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client") @@ -335,6 +346,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs index 74b6e79..a7e8810 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Client.cs @@ -20,8 +20,9 @@ namespace PlumbingRepairDatabaseImplement.Models [ForeignKey("ClientId")] public virtual List Orders{ get; set; } = new(); - - public static Client? Create(ClientBindingModel model) + [ForeignKey("ClientId")] + public virtual List Messages { get; set; } = new(); + public static Client? Create(ClientBindingModel model) { if (model == null) { diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs index 599abbe..be1fa55 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/MessageInfo.cs @@ -23,6 +23,8 @@ namespace PlumbingRepairDatabaseImplement.Models public bool IsRead { get; private set; } = false; public string? ReplyText { get; private set; } + public virtual Client? Client { get; private set; } + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null)