Илья Федотов 64ba40c90c Base.02
2024-05-01 21:05:07 +04:00

63 lines
1.6 KiB
C#

using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DinerFileImplement.Models {
public class Client : IClientModel {
public string ClientFIO { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int ID { get; set; }
public static Client? Create(ClientBindingModel? model) {
if (model == null) {
return null;
}
return new Client() {
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password,
ID = model.ID,
};
}
public static Client? Create(XElement element) {
if (element == null) {
return null;
}
return new Client() {
ClientFIO = element.Element("ClientFIO")!.Value,
Email = element.Element("Email")!.Value,
Password = element.Element("Password")!.Value,
ID = Convert.ToInt32(element.Attribute("ID")!.Value)
};
}
public void Update (ClientBindingModel? model) {
if (model == null) return;
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new() {
ClientFIO = ClientFIO,
Email = Email,
Password = Password,
ID = ID
};
public XElement GetXElement => new("Client", new XAttribute("ID", ID),
new XElement("ClientFIO", ClientFIO),
new XElement("Email", Email),
new XElement("Password", Password.ToString()));
}
}