using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.SearchModels; using PlumbingRepairContracts.StoragesContracts; using PlumbingRepairContracts.ViewModels; using PlumbingRepairListImplement.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PlumbingRepairListImplement.Implements { public class MessageInfoStorage : IMessageInfoStorage { private readonly DataListSingleton _source; public MessageInfoStorage() { _source = DataListSingleton.GetInstance(); } public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) { if (model.MessageId == null) { return null; } foreach (var message in _source.Messages) { if (model.MessageId.Equals(message.MessageId)) return message.GetViewModel; } return null; } public List GetFilteredList(MessageInfoSearchModel model) { if (!model.ClientId.HasValue) { return new(); } var result = new List(); foreach (var item in _source.Messages) { if (item.ClientId == model.ClientId) { result.Add(item.GetViewModel); } } return result; } public List GetFullList() { var result = new List(); foreach (var item in _source.Messages) { result.Add(item.GetViewModel); } return result; } public MessageInfoViewModel? Insert(MessageInfoBindingModel model) { var newMessage = Message.Create(model); if (newMessage == null) { return null; } _source.Messages.Add(newMessage); return newMessage.GetViewModel; } } }