From be8b7adbf81fb733612dff01fefe1ff2efcc93ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 18 Mar 2023 01:57:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/MessageInfoLogic.cs | 12 +++++++++++- ConfectionaryFileImplement/MessageInfoStorage.cs | 13 ++++++++++++- ConfectionaryListImplement/MessageInfoStorage.cs | 15 ++++++++++++++- .../BusinessLogicsContracts/IMessageInfoLogic.cs | 2 ++ .../StoragesContract/IMessageInfoStorage.cs | 1 + .../MessageInfoStorage.cs | 14 +++++++++++++- 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/ConfectionaryBusinessLogic/MessageInfoLogic.cs b/ConfectionaryBusinessLogic/MessageInfoLogic.cs index 99b9bb6..a4febc1 100644 --- a/ConfectionaryBusinessLogic/MessageInfoLogic.cs +++ b/ConfectionaryBusinessLogic/MessageInfoLogic.cs @@ -33,7 +33,17 @@ namespace ConfectioneryBusinessLogic return true; } - public List? ReadList(MessageInfoSearchModel? model) + public bool Update(MessageInfoBindingModel model) + { + if (_messageInfoStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public List? ReadList(MessageInfoSearchModel? model) { _logger.LogInformation("ReadList. MessageId:{MessageId}.ClientId:{ClientId} ", model?.MessageId, model?.ClientId); var list = (model == null) ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model); diff --git a/ConfectionaryFileImplement/MessageInfoStorage.cs b/ConfectionaryFileImplement/MessageInfoStorage.cs index 75505d2..e8ab119 100644 --- a/ConfectionaryFileImplement/MessageInfoStorage.cs +++ b/ConfectionaryFileImplement/MessageInfoStorage.cs @@ -55,5 +55,16 @@ namespace ConfectioneryFileImplement _source.SaveMessages(); return newMessage.GetViewModel; } - } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + var res = _source.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId)); + if (res != null) + { + res.Update(model); + _source.SaveMessages(); + } + return res?.GetViewModel; + } + } } diff --git a/ConfectionaryListImplement/MessageInfoStorage.cs b/ConfectionaryListImplement/MessageInfoStorage.cs index 249ea29..ea04f1a 100644 --- a/ConfectionaryListImplement/MessageInfoStorage.cs +++ b/ConfectionaryListImplement/MessageInfoStorage.cs @@ -72,5 +72,18 @@ namespace ConfectioneryListImplement _source.Messages.Add(newMessage); return newMessage.GetViewModel; } - } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + foreach (var message in _source.Messages) + { + if (message.MessageId.Equals(model.MessageId)) + { + message.Update(model); + return message.GetViewModel; + } + } + return null; + } + } } diff --git a/ConfectioneryContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/ConfectioneryContracts/BusinessLogicsContracts/IMessageInfoLogic.cs index ed4b54c..248770f 100644 --- a/ConfectioneryContracts/BusinessLogicsContracts/IMessageInfoLogic.cs +++ b/ConfectioneryContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -14,5 +14,7 @@ namespace ConfectioneryContracts.BusinessLogicsContracts List? ReadList(MessageInfoSearchModel? model); bool Create(MessageInfoBindingModel model); + + bool Update(MessageInfoBindingModel model); } } diff --git a/ConfectioneryContracts/StoragesContract/IMessageInfoStorage.cs b/ConfectioneryContracts/StoragesContract/IMessageInfoStorage.cs index 6bb7375..b62df06 100644 --- a/ConfectioneryContracts/StoragesContract/IMessageInfoStorage.cs +++ b/ConfectioneryContracts/StoragesContract/IMessageInfoStorage.cs @@ -18,5 +18,6 @@ namespace ConfectioneryContracts.StoragesContract MessageInfoViewModel? GetElement(MessageInfoSearchModel model); MessageInfoViewModel? Insert(MessageInfoBindingModel model); + MessageInfoViewModel? Update(MessageInfoBindingModel model); } } diff --git a/ConfectioneryDatabaseImplement/MessageInfoStorage.cs b/ConfectioneryDatabaseImplement/MessageInfoStorage.cs index d60e1c5..19b93c1 100644 --- a/ConfectioneryDatabaseImplement/MessageInfoStorage.cs +++ b/ConfectioneryDatabaseImplement/MessageInfoStorage.cs @@ -52,5 +52,17 @@ namespace ConfectioneryDatabaseImplement context.SaveChanges(); return newMessage.GetViewModel; } - } + + public MessageInfoViewModel? Update(MessageInfoBindingModel model) + { + using var context = new ConfectioneryDatabase(); + var res = context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId)); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } }