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

59 lines
1.4 KiB
C#
Raw Normal View History

2024-06-22 20:56:02 +04:00
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations;
2024-06-22 21:11:56 +04:00
using System.Runtime.Serialization;
2024-06-22 20:56:02 +04:00
namespace SewingDressesDatabaseImplement.Models
{
2024-06-22 21:11:56 +04:00
[DataContract]
2024-06-22 20:56:02 +04:00
public class MessageInfo : IMessageInfoModel
{
2024-06-22 21:11:56 +04:00
public int Id { get; set; }
2024-06-22 20:56:02 +04:00
[Key]
2024-06-22 21:11:56 +04:00
[DataMember]
2024-06-22 20:56:02 +04:00
public string MessageId { get; private set; } = string.Empty;
2024-06-22 21:11:56 +04:00
[DataMember]
2024-06-22 20:56:02 +04:00
public int? ClientId { get; private set; }
[Required]
2024-06-22 21:11:56 +04:00
[DataMember]
2024-06-22 20:56:02 +04:00
public string SenderName { get; private set; } = string.Empty;
[Required]
2024-06-22 21:11:56 +04:00
[DataMember]
2024-06-22 20:56:02 +04:00
public DateTime DateDelivery { get; private set; }
[Required]
2024-06-22 21:11:56 +04:00
[DataMember]
2024-06-22 20:56:02 +04:00
public string Subject { get; private set; } = string.Empty;
[Required]
2024-06-22 21:11:56 +04:00
[DataMember]
2024-06-22 20:56:02 +04:00
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,
};
}
}