From 269964f62dc24257d6598781e606c4dc097330ea Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Tue, 30 Apr 2024 12:52:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D1=82?= =?UTF-8?q?=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IceCreamShop/IceCreamShop/Program.cs | 52 ++++++++++--------- .../Implements/MessageInfoStorage.cs | 2 +- .../Models/MessageInfo.cs | 5 +- IceCreamShop/IceCreamShopRestApi/Program.cs | 3 +- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/IceCreamShop/IceCreamShop/Program.cs b/IceCreamShop/IceCreamShop/Program.cs index 256f6e5..aac2943 100644 --- a/IceCreamShop/IceCreamShop/Program.cs +++ b/IceCreamShop/IceCreamShop/Program.cs @@ -70,38 +70,42 @@ namespace IceCreamShop option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddSingleton(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + + services.AddSingleton(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Implements/MessageInfoStorage.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Implements/MessageInfoStorage.cs index 0aed07f..a3e5668 100644 --- a/IceCreamShop/IceCreamShopDatabaseImplement/Implements/MessageInfoStorage.cs +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Implements/MessageInfoStorage.cs @@ -39,7 +39,7 @@ namespace IceCreamShopDatabaseImplement.Implements public MessageInfoViewModel? Insert(MessageInfoBindingModel model) { using var context = new IceCreamShopDataBase(); - var newMessage = MessageInfo.Create(model); + var newMessage = MessageInfo.Create(context, model); if (newMessage == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId))) { return null; diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Models/MessageInfo.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Models/MessageInfo.cs index 6106519..4fa8b59 100644 --- a/IceCreamShop/IceCreamShopDatabaseImplement/Models/MessageInfo.cs +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Models/MessageInfo.cs @@ -22,7 +22,7 @@ namespace IceCreamShopDatabaseImplement.Models public Client? Client { get; private set; } - public static MessageInfo? Create(MessageInfoBindingModel model) + public static MessageInfo? Create(IceCreamShopDataBase context, MessageInfoBindingModel model) { if (model == null) { @@ -32,7 +32,8 @@ namespace IceCreamShopDatabaseImplement.Models { Body = model.Body, Subject = model.Subject, - ClientId = model.ClientId, + ClientId = context.Clients.FirstOrDefault(x => x.Email == model.SenderName).Id, + Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName), MessageId = model.MessageId, SenderName = model.SenderName, DateDelivery = model.DateDelivery, diff --git a/IceCreamShop/IceCreamShopRestApi/Program.cs b/IceCreamShop/IceCreamShopRestApi/Program.cs index 2cb7fea..2d505bf 100644 --- a/IceCreamShop/IceCreamShopRestApi/Program.cs +++ b/IceCreamShop/IceCreamShopRestApi/Program.cs @@ -21,7 +21,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); + +builder.Services.AddSingleton(); builder.Services.AddControllers();