Модели + хранилище + логика
This commit is contained in:
parent
8fda3c5c07
commit
6c85e1d9fa
@ -0,0 +1,79 @@
|
||||
using AbstractShopContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.BusinessLogicsContracts;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class MessageLogic : IMessageInfoLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoStorage _messageStorage;
|
||||
public MessageLogic(ILogger<CarLogic> logger, IMessageInfoStorage messageStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageStorage = messageStorage;
|
||||
}
|
||||
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList");
|
||||
var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_messageStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(MessageInfoBindingModel model, bool withParams =
|
||||
true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.MessageId))
|
||||
{
|
||||
throw new ArgumentNullException("Нет айди письма", nameof(model.MessageId));
|
||||
}
|
||||
if (!model.ClientId.HasValue)
|
||||
{
|
||||
throw new ArgumentNullException("Нет айди клиента", nameof(model.ClientId));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Body))
|
||||
{
|
||||
throw new ArgumentNullException("Нет тела письма", nameof(model.Body));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.SenderName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет отправителя письма", nameof(model.SenderName));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace AutomobilePlantContracts.BindingModels
|
||||
{
|
||||
public class MailConfigBindingModel
|
||||
{
|
||||
public string MailLogin { get; set; } = string.Empty;
|
||||
|
||||
public string MailPassword { get; set; } = string.Empty;
|
||||
|
||||
public string SmtpClientHost { get; set; } = string.Empty;
|
||||
|
||||
public int SmtpClientPort { get; set; }
|
||||
|
||||
public string PopHost { get; set; } = string.Empty;
|
||||
|
||||
public int PopPort { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
namespace AutomobilePlantContracts.BindingModels
|
||||
{
|
||||
public class MailSendInfoBindingModel
|
||||
{
|
||||
public string MailAddress { get; set; } = string.Empty;
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using AutomobilePlantDataModels.Models;
|
||||
|
||||
namespace AutomobilePlantContracts.BindingModels
|
||||
{
|
||||
public class MessageInfoBindingModel : IMessageInfoModel
|
||||
{
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateDelivery { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
|
||||
namespace AutomobilePlantContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IMessageInfoLogic
|
||||
{
|
||||
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||
|
||||
bool Create(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace AutomobilePlantContracts.SearchModel
|
||||
{
|
||||
public class MessageInfoSearchModel
|
||||
{
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string? MessageId { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
|
||||
namespace AbstractShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IMessageInfoStorage
|
||||
{
|
||||
List<MessageInfoViewModel> GetFullList();
|
||||
|
||||
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||
|
||||
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||
|
||||
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace AutomobilePlantContracts.ViewModel
|
||||
{
|
||||
public class MessageInfoViewModel : IMessageInfoModel
|
||||
{
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
[DisplayName("Отправитель")]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата письма")]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
[DisplayName("Заголовок")]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Текст")]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantDataModels.Models
|
||||
{
|
||||
public interface IMessageInfoModel
|
||||
{
|
||||
string MessageId { get; }
|
||||
|
||||
int? ClientId { get; }
|
||||
|
||||
string SenderName { get; }
|
||||
|
||||
DateTime DateDelivery { get; }
|
||||
|
||||
string Subject { get; }
|
||||
|
||||
string Body { get; }
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ namespace AutomobilePlantListImplement
|
||||
public List<Car> Cars { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
public List<MessageInfoModel> Messages { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
@ -22,6 +23,7 @@ namespace AutomobilePlantListImplement
|
||||
Cars = new List<Car>();
|
||||
Clients = new List<Client>();
|
||||
Implementers = new List<Implementer>();
|
||||
Messages = new List<MessageInfoModel>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -0,0 +1,98 @@
|
||||
using AbstractShopContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantListImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
|
||||
{
|
||||
|
||||
private readonly DataListSingleton _source;
|
||||
public MessageInfoStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.MessageId) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var message in _source.Messages)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.MessageId) && message.MessageId.Equals(model.MessageId) )
|
||||
{
|
||||
return message.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
var result = new List<MessageInfoViewModel>();
|
||||
|
||||
if (!model.ClientId.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (var message in _source.Messages)
|
||||
{
|
||||
if (message.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(message.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<MessageInfoViewModel>();
|
||||
|
||||
foreach (var message in _source.Messages)
|
||||
{
|
||||
result.Add(message.GetViewModel);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
model.MessageId = "1";
|
||||
|
||||
foreach (var message in _source.Messages)
|
||||
{
|
||||
if (model.MessageId.Equals(message.MessageId))
|
||||
{
|
||||
model.MessageId = (Convert.ToInt32(message.MessageId) +1).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
var newMes = MessageInfoModel.Create(model);
|
||||
|
||||
if (newMes == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_source.Messages.Add(newMes);
|
||||
|
||||
return newMes.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantListImplement.Models
|
||||
{
|
||||
public class MessageInfoModel : IMessageInfoModel
|
||||
{
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public static MessageInfoModel? Create(MessageInfoBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new MessageInfoModel()
|
||||
{
|
||||
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,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -29,5 +29,7 @@ namespace AutomobilePlantDataBaseImplements
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
|
||||
public virtual DbSet<MessageInfo> Messages { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace AutomobilePlantDataBaseImplements.Implements
|
||||
.Where(x => x.ClientFIO.Contains(model.ClientFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}else if (!string.IsNullOrEmpty(model.Email))
|
||||
}else if (!string.IsNullOrEmpty(model.Email)) // Поиск клиента по логину
|
||||
{
|
||||
return context.Clients
|
||||
.Where(x => x.Email.Contains(model.Email))
|
||||
|
@ -0,0 +1,68 @@
|
||||
using AbstractShopContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataBaseImplements.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantDataBaseImplements.Implements
|
||||
{
|
||||
public class MessageStorage : IMessageInfoStorage
|
||||
{
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.MessageId) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AutoPlantDataBase();
|
||||
return context.Messages
|
||||
.Include(x => x.client)
|
||||
.FirstOrDefault(x => x.MessageId.Equals(model.MessageId))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AutoPlantDataBase();
|
||||
return context.Messages
|
||||
.Include(x => x.client)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AutoPlantDataBase();
|
||||
return context.Messages
|
||||
.Include(x => x.client)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
using var context = new AutoPlantDataBase();
|
||||
var newMes = MessageInfo.Create(model);
|
||||
if (newMes == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Messages.Add(newMes);
|
||||
context.SaveChanges();
|
||||
return newMes.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomobilePlantDataBaseImplements.Models
|
||||
{
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
[Required]
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
public int? ClientId { get; set; }
|
||||
public Client client { get; private set; }
|
||||
[Required]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
public static MessageInfo? Create(MessageInfoBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new MessageInfo()
|
||||
{
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
@ -16,11 +16,13 @@ namespace AutomomilePlantFileImplement
|
||||
private readonly string CarFileName = "Car.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
private readonly string ImplementerFileName = "Implementer.xml";
|
||||
private readonly string MessageFileName = "Message.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Car> Cars { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public List<Implementer> Implementers { get; private set; }
|
||||
public List<MessageInfo> Messages { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -39,6 +41,8 @@ namespace AutomomilePlantFileImplement
|
||||
"Cars", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x
|
||||
=> x.GetXElement);
|
||||
public void SaveMessages() => SaveData(Messages, MessageFileName, "Messages", x
|
||||
=> x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x =>
|
||||
@ -50,6 +54,7 @@ namespace AutomomilePlantFileImplement
|
||||
Implementers = LoadData(ImplementerFileName, "Implementers", x =>
|
||||
Implementer.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Messages = LoadData(MessageFileName, "Message", x => MessageInfo.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||
Func<XElement, T> selectFunction)
|
||||
|
@ -0,0 +1,74 @@
|
||||
using AbstractShopContracts.StoragesContracts;
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.SearchModel;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using AutomomilePlantFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutomomilePlantFileImplement.Implements
|
||||
{
|
||||
public class MessageStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public MessageStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.MessageId) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Messages
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.MessageId) && x.MessageId.Equals(model.MessageId)))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Messages
|
||||
.Where(x => x.ClientId== model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
return source.Messages
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
if (source.Messages.Count > 0)
|
||||
{
|
||||
var id = source.Messages.Count + 1;
|
||||
model.MessageId = id.ToString();
|
||||
}
|
||||
else
|
||||
model.MessageId = "1";
|
||||
|
||||
var newMes = MessageInfo.Create(model);
|
||||
if (newMes == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Messages.Add(newMes);
|
||||
source.SaveMessages();
|
||||
return newMes.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using AutomobilePlantContracts.BindingModels;
|
||||
using AutomobilePlantContracts.ViewModel;
|
||||
using AutomobilePlantDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace AutomomilePlantFileImplement.Models
|
||||
{
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
public string MessageId {get;set;} = string.Empty;
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set;} = string.Empty;
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new MessageInfo()
|
||||
{
|
||||
MessageId = model.MessageId,
|
||||
ClientId = model.ClientId,
|
||||
SenderName = model.SenderName,
|
||||
DateDelivery = model.DateDelivery,
|
||||
Subject = model.Subject,
|
||||
Body = model.Body,
|
||||
};
|
||||
}
|
||||
public static MessageInfo? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new MessageInfo()
|
||||
{
|
||||
MessageId =element.Attribute("MessageId")!.Value,
|
||||
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
||||
SenderName = element.Attribute("SenderName")!.Value,
|
||||
DateDelivery = DateTime.Parse(element.Element("DateDelivery")!.Value),
|
||||
Subject = element.Attribute("Subject")!.Value,
|
||||
Body = element.Attribute("Body")!.Value,
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
MessageId = MessageId,
|
||||
ClientId = ClientId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
Subject = Subject,
|
||||
Body = Body,
|
||||
};
|
||||
public XElement GetXElement => new("MessageInfo",
|
||||
new XAttribute("MessageId", MessageId),
|
||||
new XElement("ClientId", ClientId.ToString()),
|
||||
new XElement("SenderName", SenderName),
|
||||
new XElement("DateDelivery", DateDelivery.ToString()),
|
||||
new XElement("Subject", Subject),
|
||||
new XElement("Body", Body)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user