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();