PIbd-21_Potapov_N.S._Securi.../SecuritySystem/SecuritySystemFileImplement/Models/Client.cs

69 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.ViewModels;
using SecuritySystemDataModels.Models;
using SecuritySystemFileImplement.Models;
using System.Reflection;
using System.Xml.Linq;
namespace SecuritySystemFileImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
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,
Email = model.Email,
Password = model.Password,
ClientFIO = model.ClientFIO
};
}
public static Client? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Client()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Email = Convert.ToString(element.Attribute("Email")!.Value),
Password = Convert.ToString(element.Attribute("Password")!.Value),
ClientFIO = Convert.ToString(element.Attribute("ClientFIO")!.Value)
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
Email = model.Email;
Password = model.Password;
ClientFIO = model.ClientFIO;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
Email = Email,
Password = Password,
ClientFIO = ClientFIO
};
public XElement GetXElement => new("Сlient",
new XAttribute("Id", Id),
new XElement("Email", Email),
new XElement("Password", Password),
new XElement("ClientFIO", ClientFIO)
);
}
}