From 6a7474bb87650f85d84e6481d09015eb3508217e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Thu, 1 Jun 2023 16:24:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B17=20-=20=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/MessageInfoStorage.cs | 77 +++++++++++++++++++ .../Models/MessageInfo.cs | 48 ++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Implements/MessageInfoStorage.cs create mode 100644 FoodOrders/AbstractFoodOrdersListImplement/Models/MessageInfo.cs diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Implements/MessageInfoStorage.cs b/FoodOrders/AbstractFoodOrdersListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..eb84506 --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,77 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.SearchModels; +using AbstractFoodOrdersContracts.StoragesContracts; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + + public MessageInfoStorage(DataListSingleton source) + { + _source = source; + } + + public List GetFullList() + { + var result = new List(); + foreach (var messageInfo in _source.MessageInfos) + { + result.Add(messageInfo.GetViewModel); + } + return result; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.MessageId) && !model.ClientId.HasValue) + { + return result; + } + foreach (var messageInfo in _source.MessageInfos) + { + if (messageInfo.ClientId == model.ClientId) + { + result.Add(messageInfo.GetViewModel); + } + } + return result; + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (string.IsNullOrEmpty(model.MessageId) && !model.ClientId.HasValue) + { + return null; + } + foreach (var messageInfo in _source.MessageInfos) + { + if (!string.IsNullOrEmpty(model.MessageId) && model.ClientId.HasValue && messageInfo.MessageId == model.MessageId && messageInfo.ClientId == model.ClientId) + { + return messageInfo.GetViewModel; + } + } + return null; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessageInfo = MessageInfo.Create(model); + if (newMessageInfo == null) + { + return null; + } + _source.MessageInfos.Add(newMessageInfo); + return newMessageInfo.GetViewModel; + } + } +} diff --git a/FoodOrders/AbstractFoodOrdersListImplement/Models/MessageInfo.cs b/FoodOrders/AbstractFoodOrdersListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..40b922b --- /dev/null +++ b/FoodOrders/AbstractFoodOrdersListImplement/Models/MessageInfo.cs @@ -0,0 +1,48 @@ +using AbstractFoodOrdersContracts.BindingModels; +using AbstractFoodOrdersContracts.ViewModels; +using AbstractFoodOrdersDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractFoodOrdersListImplement.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; } + 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, + Body = model.Body, + Subject = model.Subject, + DateDelivery = model.DateDelivery + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + Body = Body, + Subject = Subject, + DateDelivery = DateDelivery + }; + } +}