Лаб7 - фикс
This commit is contained in:
parent
3315dd4f0d
commit
6a7474bb87
@ -0,0 +1,77 @@
|
||||
using AbstractFoodOrdersContracts.BindingModels;
|
||||
using AbstractFoodOrdersContracts.SearchModels;
|
||||
using AbstractFoodOrdersContracts.StoragesContracts;
|
||||
using AbstractFoodOrdersContracts.ViewModels;
|
||||
using AbstractFoodOrdersListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public MessageInfoStorage(DataListSingleton source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<MessageInfoViewModel>();
|
||||
foreach (var messageInfo in _source.MessageInfos)
|
||||
{
|
||||
result.Add(messageInfo.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
var result = new List<MessageInfoViewModel>();
|
||||
if (string.IsNullOrEmpty(model.MessageId) && !model.ClientId.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var messageInfo in _source.MessageInfos)
|
||||
{
|
||||
if (messageInfo.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(messageInfo.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.MessageId) && !model.ClientId.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var messageInfo in _source.MessageInfos)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.MessageId) && model.ClientId.HasValue && messageInfo.MessageId == model.MessageId && messageInfo.ClientId == model.ClientId)
|
||||
{
|
||||
return messageInfo.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
var newMessageInfo = MessageInfo.Create(model);
|
||||
if (newMessageInfo == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.MessageInfos.Add(newMessageInfo);
|
||||
return newMessageInfo.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using AbstractFoodOrdersContracts.BindingModels;
|
||||
using AbstractFoodOrdersContracts.ViewModels;
|
||||
using AbstractFoodOrdersDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractFoodOrdersListImplement.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; }
|
||||
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,
|
||||
Body = model.Body,
|
||||
Subject = model.Subject,
|
||||
DateDelivery = model.DateDelivery
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
MessageId = MessageId,
|
||||
ClientId = ClientId,
|
||||
SenderName = SenderName,
|
||||
Body = Body,
|
||||
Subject = Subject,
|
||||
DateDelivery = DateDelivery
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user