Fixes
This commit is contained in:
parent
2dcc0cab18
commit
f6bc620bc7
@ -1,6 +1,7 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
using PizzeriaContracts.BindingModels;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
using PizzeriaDataModels.Enums;
|
using PizzeriaDataModels.Enums;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
@ -13,7 +14,7 @@ using System.Threading.Tasks;
|
|||||||
namespace PizzeriaDatabaseImplement.Models
|
namespace PizzeriaDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class Order
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
@ -9,10 +9,16 @@ namespace PizzeriaFileImplement
|
|||||||
private readonly string ComponentFileName = "Component.xml";
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string PizzaFileName = "Pizza.xml";
|
private readonly string PizzaFileName = "Pizza.xml";
|
||||||
|
private readonly string ClientFileName = "Client.xml";
|
||||||
|
private readonly string ImplementerFileName = "Implementer.xml";
|
||||||
|
private readonly string MessageInfoFileName = "MessageInfos.xml";
|
||||||
public List<Component> Components { get; private set; }
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Pizza> Pizzas { get; private set; }
|
public List<Pizza> Pizzas { get; private set; }
|
||||||
|
public List<Client> Clients { get; private set; }
|
||||||
|
public List<Implementer> Implementers { get; private set; }
|
||||||
|
public List<MessageInfo> MessageInfos { get; private set; }
|
||||||
|
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
@ -24,11 +30,19 @@ namespace PizzeriaFileImplement
|
|||||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||||
public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement);
|
public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
|
|
||||||
|
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||||
|
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||||
|
public void SaveMessageInfos() => SaveData(MessageInfos, MessageInfoFileName, "MessageInfos", x => x.GetXElement);
|
||||||
|
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!;
|
Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
|
Implementers = LoadData(ImplementerFileName, "Client", x => Implementer.Create(x)!)!;
|
||||||
|
MessageInfos = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!;
|
||||||
}
|
}
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
{
|
{
|
||||||
|
27
Pizzeria/PizzeriaFileImplement/ImplementationExtension.cs
Normal file
27
Pizzeria/PizzeriaFileImplement/ImplementationExtension.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using PizzeriaContracts.DI;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaFileImplement.Implements;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement
|
||||||
|
{
|
||||||
|
public class ImplementationExtension : IImplementationExtension
|
||||||
|
{
|
||||||
|
public int Priority => 1;
|
||||||
|
|
||||||
|
public void RegisterServices()
|
||||||
|
{
|
||||||
|
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IPizzaStorage, PizzaStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
Pizzeria/PizzeriaFileImplement/Implements/BackUpInfo.cs
Normal file
42
Pizzeria/PizzeriaFileImplement/Implements/BackUpInfo.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class BackUpInfo : IBackUpInfo
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
private readonly PropertyInfo[] sourceProperties;
|
||||||
|
public BackUpInfo()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
|
||||||
|
}
|
||||||
|
public List<T>? GetList<T>() where T : class, new()
|
||||||
|
{
|
||||||
|
var requredType = typeof(T);
|
||||||
|
return (List<T>?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType)
|
||||||
|
?.GetValue(source);
|
||||||
|
|
||||||
|
}
|
||||||
|
public Type? GetTypeByModelInterface(string modelInterfaceName)
|
||||||
|
{
|
||||||
|
var assembly = typeof(BackUpInfo).Assembly;
|
||||||
|
var types = assembly.GetTypes();
|
||||||
|
foreach (var type in types)
|
||||||
|
{
|
||||||
|
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
82
Pizzeria/PizzeriaFileImplement/Implements/ClientStorage.cs
Normal file
82
Pizzeria/PizzeriaFileImplement/Implements/ClientStorage.cs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ClientStorage : IClientStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public ClientStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Clients.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Clients.Where(x => (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO.Contains(model.ClientFIO)) ||
|
||||||
|
(!string.IsNullOrEmpty(model.Email) && x.Email.Contains(model.Email))).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ClientFIO) && (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password)))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Clients.FirstOrDefault(x => (!model.Id.HasValue && x.Id == model.Id) ||
|
||||||
|
(!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO) ||
|
||||||
|
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newClient = Client.Create(model);
|
||||||
|
if(newClient == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Clients.Add(newClient);
|
||||||
|
source.SaveClients();
|
||||||
|
return newClient.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1;
|
||||||
|
var client = source.Clients.FirstOrDefault(x=> x.Id == model.Id);
|
||||||
|
if(client == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
client.Update(model);
|
||||||
|
source.SaveClients();
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if(client != null)
|
||||||
|
{
|
||||||
|
source.Clients.Remove(client);
|
||||||
|
source.SaveClients();
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class MessageInfoStorage : IMessageInfoStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public MessageInfoStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<MessageInfoViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.MessageInfos.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.ClientId.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.MessageInfos.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.MessageId))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.MessageInfos.FirstOrDefault(x=>x.MessageId == model.MessageId)?.GetViewModel;
|
||||||
|
}
|
||||||
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
var newMessage = MessageInfo.Create(model);
|
||||||
|
if (newMessage == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.MessageInfos.Add(newMessage);
|
||||||
|
source.SaveMessageInfos();
|
||||||
|
return newMessage.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
79
Pizzeria/PizzeriaFileImplement/Models/Client.cs
Normal file
79
Pizzeria/PizzeriaFileImplement/Models/Client.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.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 PizzeriaFileImplement.Models
|
||||||
|
{
|
||||||
|
[DataContract]
|
||||||
|
public class Client : IClientModel
|
||||||
|
{
|
||||||
|
[DataMember]
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public string ClientFIO { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public string Email { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
public static Client? Create(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Client()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ClientFIO = model.ClientFIO,
|
||||||
|
Email = model.Email,
|
||||||
|
Password = model.Password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Client? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Client()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ClientFIO = element.Element("ClientFIO")!.Value,
|
||||||
|
Email = element.Element("Email")!.Value,
|
||||||
|
Password = element.Element("Password")!.Value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClientFIO = model.ClientFIO;
|
||||||
|
Email = model.Email;
|
||||||
|
Password = model.Password;
|
||||||
|
}
|
||||||
|
public ClientViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ClientFIO = ClientFIO,
|
||||||
|
Email = Email,
|
||||||
|
Password = Password,
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Client",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ClientFIO", ClientFIO),
|
||||||
|
new XElement("Email", Email),
|
||||||
|
new XElement("Password", Password));
|
||||||
|
}
|
||||||
|
}
|
86
Pizzeria/PizzeriaFileImplement/Models/Implementer.cs
Normal file
86
Pizzeria/PizzeriaFileImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.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 PizzeriaFileImplement.Models
|
||||||
|
{
|
||||||
|
[DataContract]
|
||||||
|
public class Implementer : IImplementerModel
|
||||||
|
{
|
||||||
|
[DataMember]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DataMember]
|
||||||
|
public string ImplementerFIO { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public int WorkExperience { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public int Qualification { get; set; }
|
||||||
|
public static Implementer? Create(ImplementerBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Implementer()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ImplementerFIO = model.ImplementerFIO,
|
||||||
|
Password = model.Password,
|
||||||
|
WorkExperience = model.WorkExperience,
|
||||||
|
Qualification = model.Qualification
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Implementer? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Implementer()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ImplementerFIO = element.Element("ImplementerFIO")!.Value,
|
||||||
|
Password = element.Element("Password")!.Value,
|
||||||
|
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
|
||||||
|
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ImplementerFIO = model.ImplementerFIO;
|
||||||
|
Password = model.Password;
|
||||||
|
WorkExperience = model.WorkExperience;
|
||||||
|
Qualification = model.Qualification;
|
||||||
|
}
|
||||||
|
public ImplementerViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ImplementerFIO = ImplementerFIO,
|
||||||
|
Password = Password,
|
||||||
|
WorkExperience = WorkExperience,
|
||||||
|
Qualification = Qualification
|
||||||
|
};
|
||||||
|
public XElement GetXElement=>new("Implementer",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ImplementerFIO", ImplementerFIO),
|
||||||
|
new XElement("Password", Password),
|
||||||
|
new XElement("WorkExperience", WorkExperience.ToString()),
|
||||||
|
new XElement("Qualification", Qualification.ToString()));
|
||||||
|
}
|
||||||
|
}
|
89
Pizzeria/PizzeriaFileImplement/Models/MessageInfo.cs
Normal file
89
Pizzeria/PizzeriaFileImplement/Models/MessageInfo.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Models
|
||||||
|
{
|
||||||
|
[DataContract]
|
||||||
|
public class MessageInfo : IMessageInfoModel
|
||||||
|
{
|
||||||
|
[DataMember]
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[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; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public string Subject { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public string Body { get; private 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 static MessageInfo? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
string clientId = element.Element("ClientId")!.Value;
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
MessageId = element.Attribute("MessageId")!.Value,
|
||||||
|
ClientId = string.IsNullOrEmpty(clientId) ? null : Convert.ToInt32(clientId),
|
||||||
|
SenderName = element.Element("SenderName")!.Value,
|
||||||
|
DateDelivery = Convert.ToDateTime(element.Element("DateDelivery")!.Value),
|
||||||
|
Subject = element.Element("Subject")!.Value,
|
||||||
|
Body = element.Element("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));
|
||||||
|
}
|
||||||
|
}
|
@ -20,4 +20,8 @@
|
|||||||
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user