85 lines
2.8 KiB
C#
85 lines
2.8 KiB
C#
using FurnitureAssemblyContracts.BindingModels;
|
|
using FurnitureAssemblyContracts.ViewModels;
|
|
using FurnitureAssemblyDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Serialization;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
|
|
namespace FurnitureAssemblyFileImplement.Models
|
|
{
|
|
[DataContract]
|
|
public class MessageInfo : IMessageInfoModel
|
|
{
|
|
[DataMember]
|
|
public string MessageId { get; private set; } = string.Empty;
|
|
[DataMember]
|
|
public int? ClientId { get; private set; }
|
|
[DataMember]
|
|
public string SenderName { get; private set; } = string.Empty;
|
|
[DataMember]
|
|
public DateTime DateDelivery { get; private set; } = DateTime.Now;
|
|
[DataMember]
|
|
public string Subject { get; private set; } = string.Empty;
|
|
[DataMember]
|
|
public string Body { get; private set; } = string.Empty;
|
|
public int Id => throw new NotImplementedException();
|
|
|
|
public static MessageInfo? Create(MessageInfoBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new()
|
|
{
|
|
MessageId = model.MessageId,
|
|
ClientId = model.ClientId,
|
|
Body = model.Body,
|
|
Subject = model.Subject,
|
|
SenderName = model.SenderName,
|
|
DateDelivery = model.DateDelivery,
|
|
};
|
|
}
|
|
|
|
public static MessageInfo? Create(XElement element)
|
|
{
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new MessageInfo()
|
|
{
|
|
MessageId = element.Element("MessageId")!.Value,
|
|
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
|
Body = element.Element("Body")!.Value,
|
|
Subject = element.Element("Subject")!.Value,
|
|
SenderName = element.Element("SenderName")!.Value,
|
|
DateDelivery = DateTime.ParseExact(element.Element("DateDelivery")!.Value, "G", null)
|
|
};
|
|
}
|
|
|
|
public MessageInfoViewModel GetViewModel => new()
|
|
{
|
|
Body = Body,
|
|
Subject = Subject,
|
|
ClientId = ClientId,
|
|
MessageId = MessageId,
|
|
SenderName = SenderName,
|
|
DateDelivery = DateDelivery,
|
|
};
|
|
|
|
public XElement GetXElement => new("MessageInfo",
|
|
new XElement("SenderName", SenderName),
|
|
new XElement("ClientId", ClientId),
|
|
new XElement("DateDelivery", DateDelivery),
|
|
new XAttribute("MessageId", MessageId),
|
|
new XElement("Body", Body),
|
|
new XElement("Subject", Subject)
|
|
);
|
|
}
|
|
}
|