PIbd_23_Kislitsa_E.D_Diner/Diner/DinerDataBaseImplement/Models/MessageInfo.cs

67 lines
1.7 KiB
C#
Raw Permalink Normal View History

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;
namespace DinerDataBaseImplement.Models
{
2024-05-12 15:13:03 +04:00
[DataContract]
public class MessageInfo : IMessageInfoModel
{
[Key]
2024-05-12 15:13:03 +04:00
[DataMember]
public string MessageId { get; set; } = string.Empty;
public int? ClientId { get; set; }
2024-05-11 23:56:38 +04:00
public string SenderName { get; set; } = string.Empty;
2024-05-11 23:56:38 +04:00
public DateTime DateDelivery { get; set; } = DateTime.Now;
2024-05-11 23:56:38 +04:00
public string Subject { get; set; } = string.Empty;
2024-05-11 23:56:38 +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)
{
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),
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
};
}
}