2024-05-07 00:29:58 +04:00
|
|
|
|
using DinerContracts.BindingModels;
|
|
|
|
|
using DinerContracts.ViewModels;
|
|
|
|
|
using DinerDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-05-12 15:13:03 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
2024-05-07 00:29:58 +04:00
|
|
|
|
|
|
|
|
|
namespace DinerDataBaseImplement.Models
|
|
|
|
|
{
|
2024-05-12 15:13:03 +04:00
|
|
|
|
[DataContract]
|
2024-05-07 00:29:58 +04:00
|
|
|
|
public class MessageInfo : IMessageInfoModel
|
|
|
|
|
{
|
|
|
|
|
[Key]
|
2024-05-12 15:13:03 +04:00
|
|
|
|
[DataMember]
|
2024-05-07 00:29:58 +04:00
|
|
|
|
public string MessageId { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public int? ClientId { get; set; }
|
|
|
|
|
|
2024-05-11 23:56:38 +04:00
|
|
|
|
|
2024-05-07 00:29:58 +04:00
|
|
|
|
public string SenderName { get; set; } = string.Empty;
|
|
|
|
|
|
2024-05-11 23:56:38 +04:00
|
|
|
|
|
2024-05-07 00:29:58 +04:00
|
|
|
|
public DateTime DateDelivery { get; set; } = DateTime.Now;
|
|
|
|
|
|
2024-05-11 23:56:38 +04:00
|
|
|
|
|
2024-05-07 00:29:58 +04:00
|
|
|
|
public string Subject { get; set; } = string.Empty;
|
|
|
|
|
|
2024-05-11 23:56:38 +04:00
|
|
|
|
|
2024-05-07 00:29:58 +04:00
|
|
|
|
public string Body { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public virtual Client? Client { get; set; }
|
|
|
|
|
|
2024-05-11 23:56:38 +04:00
|
|
|
|
public static MessageInfo? Create(DinerDatabase context, MessageInfoBindingModel model)
|
2024-05-07 00:29:58 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new MessageInfo()
|
|
|
|
|
{
|
|
|
|
|
MessageId = model.MessageId,
|
|
|
|
|
ClientId = model.ClientId,
|
2024-05-11 23:56:38 +04:00
|
|
|
|
Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName),
|
2024-05-07 00:29:58 +04:00
|
|
|
|
SenderName = model.SenderName,
|
|
|
|
|
Body = model.Body,
|
|
|
|
|
DateDelivery = model.DateDelivery,
|
|
|
|
|
Subject = model.Subject
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MessageInfoViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
MessageId = MessageId,
|
|
|
|
|
ClientId = ClientId,
|
|
|
|
|
SenderName = SenderName,
|
|
|
|
|
Body = Body,
|
|
|
|
|
DateDelivery = DateDelivery,
|
|
|
|
|
Subject = Subject
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|