Реализовал хранение писем в списке
This commit is contained in:
parent
dbc3979d0c
commit
ae4d111f32
@ -10,6 +10,7 @@ namespace SecuritySystemListImplement
|
||||
public List<Secure> Secures { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
public List<MessageInfo> MessageInfos { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
@ -17,6 +18,7 @@ namespace SecuritySystemListImplement
|
||||
Secures = new List<Secure>();
|
||||
Clients = new List<Client>();
|
||||
Implementers = new List<Implementer>();
|
||||
MessageInfos = new List<MessageInfo>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -0,0 +1,45 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.SearchModels;
|
||||
using SecuritySystemContracts.StoragesContracts;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
|
||||
namespace SecuritySystemListImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public MessageInfoStorage(DataListSingleton source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
return GetFilteredList(model).FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
var messageInfos = GetFullList();
|
||||
if (!string.IsNullOrEmpty(model.MessageId))
|
||||
{
|
||||
messageInfos = messageInfos.Where(x => x.MessageId == model.MessageId).ToList();
|
||||
}
|
||||
if (model.ClientId != null)
|
||||
{
|
||||
messageInfos = messageInfos.Where(x => x.ClientId == model.ClientId).ToList();
|
||||
}
|
||||
return messageInfos;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
return _source.MessageInfos.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using SecuritySystemContracts.BindingModels;
|
||||
using SecuritySystemContracts.ViewModels;
|
||||
using SecuritySystemDataModels.Models;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SecuritySystemListImplement.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 void Update(MessageInfoBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
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