добавила реализацию для первого хранилища
This commit is contained in:
parent
e8c8552e9b
commit
e19a04a5a3
@ -10,6 +10,7 @@ namespace SushiBarListImplement
|
||||
public List<Sushi> Sushis { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
public List<MessageInfo> Messages { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
@ -17,6 +18,7 @@ namespace SushiBarListImplement
|
||||
Sushis = new List<Sushi>();
|
||||
Clients = new List<Client>();
|
||||
Implementers = new List<Implementer>();
|
||||
Messages = new List<MessageInfo>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
71
SushiBarListImplements/Implements/MessageInfoStorage.cs
Normal file
71
SushiBarListImplements/Implements/MessageInfoStorage.cs
Normal file
@ -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<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
var list = new List<MessageInfoViewModel>();
|
||||
foreach (var msg in source.Messages)
|
||||
{
|
||||
if (msg.ClientId.HasValue && model.ClientId == msg.ClientId)
|
||||
{
|
||||
list.Add(msg.GetViewModel);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
var list = new List<MessageInfoViewModel>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
45
SushiBarListImplements/Models/MessageInfo.cs
Normal file
45
SushiBarListImplements/Models/MessageInfo.cs
Normal file
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user