53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
|
using PlumbingRepairContracts.BindingModels;
|
|||
|
using PlumbingRepairContracts.SearchModels;
|
|||
|
using PlumbingRepairContracts.StoragesContracts;
|
|||
|
using PlumbingRepairContracts.ViewModels;
|
|||
|
using PlumbingRepairDatabaseImplement.Models;
|
|||
|
|
|||
|
namespace PlumbingRepairDatabaseImplement.Implements
|
|||
|
{
|
|||
|
public class MessageInfoStorage : IMessageInfoStorage
|
|||
|
{
|
|||
|
public List<MessageInfoViewModel> GetFullList()
|
|||
|
{
|
|||
|
using var context = new PlumbingRepairDatabase();
|
|||
|
return context.Messages
|
|||
|
.Select(x => x.GetViewModel)
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
|
|||
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
|||
|
{
|
|||
|
using var context = new PlumbingRepairDatabase();
|
|||
|
return context.Messages
|
|||
|
.Where(x => x.ClientId == model.ClientId)
|
|||
|
.Select(x => x.GetViewModel)
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
|
|||
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
|||
|
{
|
|||
|
using var context = new PlumbingRepairDatabase();
|
|||
|
if (model.MessageId != null)
|
|||
|
{
|
|||
|
return context.Messages
|
|||
|
.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
|||
|
{
|
|||
|
using var context = new PlumbingRepairDatabase();
|
|||
|
var newMessageInfo = MessageInfo.Create(model);
|
|||
|
|
|||
|
if (newMessageInfo == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId)))
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
context.Messages.Add(newMessageInfo);
|
|||
|
context.SaveChanges();
|
|||
|
return newMessageInfo.GetViewModel;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|