2023-05-17 10:20:24 +04:00
|
|
|
|
using PizzeriaContracts.BindingModels;
|
|
|
|
|
using PizzeriaContracts.SearchModels;
|
|
|
|
|
using PizzeriaContracts.StoragesContracts;
|
|
|
|
|
using PizzeriaContracts.ViewModels;
|
|
|
|
|
using PizzeriaFileImplement.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace PizzeriaFileImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class MessageInfoStorage : IMessageInfoStorage
|
|
|
|
|
{
|
|
|
|
|
private readonly DataFileSingleton source;
|
|
|
|
|
public MessageInfoStorage()
|
|
|
|
|
{
|
|
|
|
|
source = DataFileSingleton.GetInstance();
|
|
|
|
|
}
|
|
|
|
|
public List<MessageInfoViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
return source.MessageInfos.Select(x => x.GetViewModel).ToList();
|
|
|
|
|
}
|
|
|
|
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (!model.ClientId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
return source.MessageInfos.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
|
|
|
|
}
|
|
|
|
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(model.MessageId))
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
return source.MessageInfos.FirstOrDefault(x=>x.MessageId == model.MessageId)?.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var newMessage = MessageInfo.Create(model);
|
|
|
|
|
if (newMessage == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
source.MessageInfos.Add(newMessage);
|
|
|
|
|
source.SaveMessageInfos();
|
|
|
|
|
return newMessage.GetViewModel;
|
|
|
|
|
}
|
2023-06-14 14:25:52 +04:00
|
|
|
|
|
|
|
|
|
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2023-05-17 10:20:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|