From e7d0077ce46ca9ef7a04f371ddffeebd9292e067 Mon Sep 17 00:00:00 2001 From: bocchanskyy Date: Tue, 30 Apr 2024 04:25:43 +0400 Subject: [PATCH] small fix with relation between entities --- .../BusinessLogics/MessageInfoLogic.cs | 2 +- ...signer.cs => 20240430002234_InitialCreate.Designer.cs} | 8 +++++--- ...123_Init-Create.cs => 20240430002234_InitialCreate.cs} | 2 +- .../Migrations/ComputersShopDataBaseModelSnapshot.cs | 4 +++- .../ComputersShopDataBaseImplement/Models/Message.cs | 2 ++ .../ComputersShopFileImplement/DataFileSingleton.cs | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) rename ComputersShop/ComputersShopDataBaseImplement/Migrations/{20240418105123_Init-Create.Designer.cs => 20240430002234_InitialCreate.Designer.cs} (98%) rename ComputersShop/ComputersShopDataBaseImplement/Migrations/{20240418105123_Init-Create.cs => 20240430002234_InitialCreate.cs} (99%) diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 26fd495..618fa72 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -82,7 +82,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics }); if (element == null) { - _logger.LogWarning("Не удалоссь найти клиента, отправившего письмо с адреса Email:{Email}", model.SenderName); + _logger.LogWarning("Не удалось найти клиента, отправившего письмо с адреса Email:{Email}", model.SenderName); } else { diff --git a/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240418105123_Init-Create.Designer.cs b/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240430002234_InitialCreate.Designer.cs similarity index 98% rename from ComputersShop/ComputersShopDataBaseImplement/Migrations/20240418105123_Init-Create.Designer.cs rename to ComputersShop/ComputersShopDataBaseImplement/Migrations/20240430002234_InitialCreate.Designer.cs index 8c7fd9c..161dc1b 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240418105123_Init-Create.Designer.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240430002234_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace ComputersShopDataBaseImplement.Migrations { [DbContext(typeof(ComputersShopDataBase))] - [Migration("20240418105123_Init-Create")] - partial class InitCreate + [Migration("20240430002234_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -237,9 +237,11 @@ namespace ComputersShopDataBaseImplement.Migrations modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Message", b => { - b.HasOne("ComputersShopDataBaseImplement.Models.Client", null) + b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client") .WithMany("Messages") .HasForeignKey("ClientId"); + + b.Navigation("Client"); }); modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => diff --git a/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240418105123_Init-Create.cs b/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240430002234_InitialCreate.cs similarity index 99% rename from ComputersShop/ComputersShopDataBaseImplement/Migrations/20240418105123_Init-Create.cs rename to ComputersShop/ComputersShopDataBaseImplement/Migrations/20240430002234_InitialCreate.cs index a29f95b..556c255 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240418105123_Init-Create.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Migrations/20240430002234_InitialCreate.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace ComputersShopDataBaseImplement.Migrations { /// - public partial class InitCreate : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/ComputersShop/ComputersShopDataBaseImplement/Migrations/ComputersShopDataBaseModelSnapshot.cs b/ComputersShop/ComputersShopDataBaseImplement/Migrations/ComputersShopDataBaseModelSnapshot.cs index 5e2413c..c4f6fe2 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Migrations/ComputersShopDataBaseModelSnapshot.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Migrations/ComputersShopDataBaseModelSnapshot.cs @@ -234,9 +234,11 @@ namespace ComputersShopDataBaseImplement.Migrations modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Message", b => { - b.HasOne("ComputersShopDataBaseImplement.Models.Client", null) + b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client") .WithMany("Messages") .HasForeignKey("ClientId"); + + b.Navigation("Client"); }); modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => diff --git a/ComputersShop/ComputersShopDataBaseImplement/Models/Message.cs b/ComputersShop/ComputersShopDataBaseImplement/Models/Message.cs index 88295d9..269d6be 100644 --- a/ComputersShop/ComputersShopDataBaseImplement/Models/Message.cs +++ b/ComputersShop/ComputersShopDataBaseImplement/Models/Message.cs @@ -17,6 +17,8 @@ namespace ComputersShopDataBaseImplement.Models public int? ClientId { get; private set; } + public virtual Client? Client { get; set; } + public string SenderName { get; private set; } = string.Empty; public DateTime DateDelivery { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); diff --git a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs index 5795cf2..704cd0e 100644 --- a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs +++ b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs @@ -47,7 +47,7 @@ namespace ComputersShopFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; - Messages = LoadData(MessageFileName, "Message", x => Message.Create(x)); + Messages = LoadData(MessageFileName, "Message", x => Message.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) {