using FoodOrdersContracts.BindingModels; using FoodOrdersContracts.ViewModels; using FoodOrdersDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Runtime.Serialization; namespace FoodOrdersDatabaseImplement.Models { [DataContract] public class MessageInfo : IMessageInfoModel { [NotMapped] public int Id { get; private set; } [DataMember] [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public string MessageId { get; set; } = string.Empty; [DataMember] public int? ClientId { get; set; } [DataMember] [Required] public string SenderName { get; set; } = string.Empty; [DataMember] [Required] public DateTime DateDelivery { get; set; } [DataMember] [Required] public string Subject { get; set; } = string.Empty; [DataMember] [Required] public string Body { get; set; } = string.Empty; public virtual Client? Client { get; private set; } public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) { return null; } return new() { Body = model.Body, Subject = model.Subject, ClientId = model.ClientId, MessageId = model.MessageId, SenderName = model.SenderName, DateDelivery = model.DateDelivery, }; } public MessageInfoViewModel GetViewModel => new() { Body = Body, Subject = Subject, ClientId = ClientId, MessageId = MessageId, SenderName = SenderName, DateDelivery = DateDelivery, }; } }