61 lines
1.5 KiB
C#
61 lines
1.5 KiB
C#
|
using GiftShopContracts.BindingModels;
|
|||
|
using GiftShopContracts.SearchModels;
|
|||
|
using GiftShopContracts.StoragesContracts;
|
|||
|
using GiftShopContracts.ViewModels;
|
|||
|
using GiftShopListImplement.Models;
|
|||
|
|
|||
|
namespace GiftShopListImplement.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)
|
|||
|
{
|
|||
|
var result = new List<MessageInfoViewModel>();
|
|||
|
foreach (var message in _source.Messages)
|
|||
|
{
|
|||
|
if (message.ClientId.HasValue && message.ClientId == model.ClientId)
|
|||
|
{
|
|||
|
result.Add(message.GetViewModel);
|
|||
|
}
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public List<MessageInfoViewModel> GetFullList()
|
|||
|
{
|
|||
|
var result = new List<MessageInfoViewModel>();
|
|||
|
foreach (var message in _source.Messages)
|
|||
|
{
|
|||
|
result.Add(message.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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|