67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
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;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace DinerDataBaseImplement.Models
|
|
{
|
|
[DataContract]
|
|
public class MessageInfo : IMessageInfoModel
|
|
{
|
|
[Key]
|
|
[DataMember]
|
|
public string MessageId { get; set; } = string.Empty;
|
|
|
|
public int? ClientId { get; set; }
|
|
|
|
|
|
public string SenderName { get; set; } = string.Empty;
|
|
|
|
|
|
public DateTime DateDelivery { get; set; } = DateTime.Now;
|
|
|
|
|
|
public string Subject { get; set; } = string.Empty;
|
|
|
|
|
|
public string Body { get; set; } = string.Empty;
|
|
|
|
public virtual Client? Client { get; set; }
|
|
|
|
public static MessageInfo? Create(DinerDatabase context, MessageInfoBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new MessageInfo()
|
|
{
|
|
MessageId = model.MessageId,
|
|
ClientId = model.ClientId,
|
|
Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName),
|
|
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
|
|
};
|
|
}
|
|
}
|