PIbd-23_Ivanov_V.N._Pizzeria/Pizzeria/PizzeriaDatabaseImplement/Models/MessageInfo.cs

75 lines
1.7 KiB
C#
Raw Permalink Normal View History

2024-04-02 16:35:18 +04:00
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.ViewModels;
using PizzeriaDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2024-04-03 17:52:29 +04:00
using System.Runtime.Serialization;
2024-04-02 16:35:18 +04:00
namespace PizzeriaDatabaseImplement.Models
{
public class MessageInfo : IMessageInfoModel
{
2024-04-03 17:52:29 +04:00
[NotMapped]
public int Id { get; private set; }
[DataMember]
[Key]
2024-04-02 16:35:18 +04:00
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string MessageId { get; set; } = string.Empty;
2024-04-03 17:52:29 +04:00
[DataMember]
public int? ClientId { get; set; }
2024-04-02 16:35:18 +04:00
public virtual Client? Client { get; set; }
2024-04-03 17:52:29 +04:00
[DataMember]
[Required]
2024-04-02 16:35:18 +04:00
public string SenderName { get; set; } = string.Empty;
2024-04-03 17:52:29 +04:00
[DataMember]
[Required]
2024-04-02 16:35:18 +04:00
public DateTime DateDelivery { get; set; }
2024-04-03 17:52:29 +04:00
[DataMember]
[Required]
2024-04-02 16:35:18 +04:00
public string Subject { get; set; } = string.Empty;
2024-04-03 17:52:29 +04:00
[DataMember]
[Required]
2024-04-02 16:35:18 +04:00
public string Body { get; set; } = string.Empty;
public static MessageInfo? Create(MessageInfoBindingModel? model)
{
if (model == null)
{
return null;
}
return new()
{
MessageId = model.MessageId,
ClientId = model.ClientId,
SenderName = model.SenderName,
DateDelivery = model.DateDelivery,
Subject = model.Subject,
Body = model.Body,
};
}
public MessageInfoViewModel GetViewModel => new()
{
MessageId = MessageId,
ClientId = ClientId,
SenderName = SenderName,
DateDelivery = DateDelivery,
Subject = Subject,
Body = Body
};
}
}