2024-05-04 21:12:13 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using SushiBarContracts.BindingModel;
|
|
|
|
|
using SushiBarContracts.SearchModel;
|
|
|
|
|
using SushiBarContracts.StoragesContracts;
|
|
|
|
|
using SushiBarContracts.ViewModels;
|
|
|
|
|
using SushiBarDatabaseImplement.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SushiBarDatabaseImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class MessageInfoStorage : IMessageInfoStorage
|
|
|
|
|
{
|
|
|
|
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new SushiBarDatabase();
|
|
|
|
|
if(string.IsNullOrEmpty(model.MessageId)) return null;
|
|
|
|
|
return context.Messages
|
|
|
|
|
.Include(x => x.Client)
|
|
|
|
|
.FirstOrDefault(x => x.MessageId == model.MessageId)?
|
|
|
|
|
.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new SushiBarDatabase();
|
|
|
|
|
if (model.ClientId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return context.Messages
|
|
|
|
|
.Include(x => x.Client)
|
|
|
|
|
.Where(x => x.ClientId == model.ClientId)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<MessageInfoViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
using var context = new SushiBarDatabase();
|
|
|
|
|
return context.Messages
|
|
|
|
|
.Include(x => x.Client)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new SushiBarDatabase();
|
|
|
|
|
var newMessage = MessageInfo.Create(model);
|
2024-05-06 00:26:46 +04:00
|
|
|
|
if (newMessage == null) return null;
|
2024-05-04 21:12:13 +04:00
|
|
|
|
context.Messages.Add(newMessage);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return newMessage.GetViewModel;
|
2024-05-06 00:26:46 +04:00
|
|
|
|
|
|
|
|
|
/* using var context = new SushiBarDatabase();
|
|
|
|
|
model.ClientId = context.Clients.FirstOrDefault(x => x.Email.Equals(model.SenderName))?.Id;
|
|
|
|
|
var message = MessageInfo.Create(model);
|
|
|
|
|
if (message == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId)))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
context.Messages.Add(message);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return message.GetViewModel;*/
|
2024-05-04 21:12:13 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|