From ae4d111f326b4c0eadc84be4c123984ce5334881 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 13:28:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=B8=D1=81=D0=B5=D0=BC=20=D0=B2=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataListSingleton.cs | 2 + .../Implements/MessageInfoStorage.cs | 45 +++++++++++++++ .../Models/MessageInfo.cs | 55 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Models/MessageInfo.cs diff --git a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs index ad69514..bcb42c0 100644 --- a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs +++ b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs @@ -10,6 +10,7 @@ namespace SecuritySystemListImplement public List Secures { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List MessageInfos { get; set; } private DataListSingleton() { Components = new List(); @@ -17,6 +18,7 @@ namespace SecuritySystemListImplement Secures = new List(); Clients = new List(); Implementers = new List(); + MessageInfos = new List(); } public static DataListSingleton GetInstance() { diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..2f68309 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,45 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + public MessageInfoStorage(DataListSingleton source) + { + _source = source; + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + return GetFilteredList(model).FirstOrDefault(); + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + var messageInfos = GetFullList(); + if (!string.IsNullOrEmpty(model.MessageId)) + { + messageInfos = messageInfos.Where(x => x.MessageId == model.MessageId).ToList(); + } + if (model.ClientId != null) + { + messageInfos = messageInfos.Where(x => x.ClientId == model.ClientId).ToList(); + } + return messageInfos; + } + + public List GetFullList() + { + return _source.MessageInfos.Select(x => x.GetViewModel).ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/MessageInfo.cs b/SecuritySystem/SecuritySystemListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..5d92b57 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/MessageInfo.cs @@ -0,0 +1,55 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using System.Reflection; + +namespace SecuritySystemListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + public int? ClientId { get; set; } + public string SenderName { get; set; } = string.Empty; + public DateTime DateDelivery { get; set; } = DateTime.Now; + public string Subject { get; set; } = string.Empty; + public string Body { get; set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body, + }; + } + public void Update(MessageInfoBindingModel? model) + { + if (model == null) + { + return; + } + ClientId = model.ClientId; + SenderName = model.SenderName; + DateDelivery = model.DateDelivery; + Subject = model.Subject; + Body = model.Body; + } + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body, + }; + } +}