2024-05-14 11:30:42 +04:00
|
|
|
|
using FurnitureAssemblyContracts.BindingModels;
|
|
|
|
|
using FurnitureAssemblyContracts.SearchModels;
|
|
|
|
|
using FurnitureAssemblyContracts.StoragesContracts;
|
|
|
|
|
using FurnitureAssemblyContracts.ViewModels;
|
|
|
|
|
using FurnitureAssemblyDatabaseImplement.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
|
|
|
|
|
namespace FurnitureAssemblyDatabaseImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class MessageInfoStorage : IMessageInfoStorage
|
|
|
|
|
{
|
|
|
|
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.MessageId == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new FurnitureAssemblyDatabase();
|
|
|
|
|
|
|
|
|
|
return context.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId))?.GetViewModel;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (!model.ClientId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
using var context = new FurnitureAssemblyDatabase();
|
2024-05-14 11:56:24 +04:00
|
|
|
|
return context.Messages
|
|
|
|
|
.Where(x => x.ClientId == model.ClientId)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
2024-05-14 11:30:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MessageInfoViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
using var context = new FurnitureAssemblyDatabase();
|
2024-05-14 11:56:24 +04:00
|
|
|
|
return context.Messages
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
2024-05-14 11:30:42 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var newMessage = MessageInfo.Create(model);
|
|
|
|
|
if (newMessage == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new FurnitureAssemblyDatabase();
|
|
|
|
|
context.Messages.Add(newMessage);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return newMessage.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|