2024-05-04 18:26:36 +04:00
|
|
|
|
using FlowerShopContracts.BindingModels;
|
|
|
|
|
using FlowerShopContracts.SearchModels;
|
|
|
|
|
using FlowerShopContracts.StoragesContracts;
|
|
|
|
|
using FlowerShopContracts.ViewModels;
|
2024-05-07 17:36:18 +04:00
|
|
|
|
using FlowerShopListImplement.Models;
|
|
|
|
|
|
2024-05-04 18:26:36 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FlowerShopListImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class MessageInfoStorage : IMessageInfoStorage
|
|
|
|
|
{
|
|
|
|
|
private readonly DataListSingleton _source;
|
|
|
|
|
public MessageInfoStorage()
|
|
|
|
|
{
|
|
|
|
|
_source = DataListSingleton.GetInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
foreach (var message in _source.Messages)
|
|
|
|
|
{
|
|
|
|
|
if (model.MessageId != null && model.MessageId.Equals(message.MessageId))
|
|
|
|
|
return message.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
List<MessageInfoViewModel> result = new();
|
|
|
|
|
foreach (var item in _source.Messages)
|
|
|
|
|
{
|
|
|
|
|
if (item.ClientId.HasValue && item.ClientId == model.ClientId)
|
|
|
|
|
{
|
|
|
|
|
result.Add(item.GetViewModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MessageInfoViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
List<MessageInfoViewModel> result = new();
|
|
|
|
|
foreach (var item in _source.Messages)
|
|
|
|
|
{
|
|
|
|
|
result.Add(item.GetViewModel);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var newMessage = MessageInfo.Create(model);
|
|
|
|
|
if (newMessage == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_source.Messages.Add(newMessage);
|
|
|
|
|
return newMessage.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|