diff --git a/SushiBarListImplements/DataListSingleton.cs b/SushiBarListImplements/DataListSingleton.cs index a22b5fa..d4ccb6f 100644 --- a/SushiBarListImplements/DataListSingleton.cs +++ b/SushiBarListImplements/DataListSingleton.cs @@ -10,6 +10,7 @@ namespace SushiBarListImplement public List Sushis { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List Messages { get; set; } private DataListSingleton() { Components = new List(); @@ -17,6 +18,7 @@ namespace SushiBarListImplement Sushis = new List(); Clients = new List(); Implementers = new List(); + Messages = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBarListImplements/Implements/MessageInfoStorage.cs b/SushiBarListImplements/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..f7c629b --- /dev/null +++ b/SushiBarListImplements/Implements/MessageInfoStorage.cs @@ -0,0 +1,71 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.SearchModel; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement; +using SushiBarListImplements.Models; + +namespace SushiBarListImplements.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton source; + + public MessageInfoStorage(DataListSingleton source) + { + this.source = source; + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if(string.IsNullOrEmpty(model.MessageId) || !model.ClientId.HasValue) + { + return null; + } + + foreach (var message in source.Messages) + { + if (message.MessageId.Equals(model.MessageId)) + { + return message.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + var list = new List(); + foreach (var msg in source.Messages) + { + if (msg.ClientId.HasValue && model.ClientId == msg.ClientId) + { + list.Add(msg.GetViewModel); + } + } + return list; + } + + public List GetFullList() + { + var list = new List(); + foreach (var msg in source.Messages) + { + list.Add(msg.GetViewModel); + } + return list; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + source.Messages.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/SushiBarListImplements/Models/MessageInfo.cs b/SushiBarListImplements/Models/MessageInfo.cs new file mode 100644 index 0000000..691dc0d --- /dev/null +++ b/SushiBarListImplements/Models/MessageInfo.cs @@ -0,0 +1,45 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.ViewModels; +using SushiBarDataModels; + +namespace SushiBarListImplements.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 MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body, + }; + } +}