PIbd22_Kuznetsov_A.V._Sewin.../SewingDresses/SewingDressesDatabaseImplement/Models/MessageInfo.cs

59 lines
1.4 KiB
C#

using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace SewingDressesDatabaseImplement.Models
{
[DataContract]
public class MessageInfo : IMessageInfoModel
{
public int Id { get; set; }
[Key]
[DataMember]
public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; }
[Required]
[DataMember]
public string SenderName { get; private set; } = string.Empty;
[Required]
[DataMember]
public DateTime DateDelivery { get; private set; }
[Required]
[DataMember]
public string Subject { get; private set; } = string.Empty;
[Required]
[DataMember]
public string Body { get; private set; } = string.Empty;
public virtual Client? Client { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)
{
return null;
}
return new MessageInfo
{
MessageId = model.MessageId,
ClientId = model.ClientId,
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,
};
}
}