PIbd22_Kuznetsov_A.V._Sewin.../SewingDresses/SewingDressesFileImplement/Models/Implement.cs

77 lines
2.1 KiB
C#

using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SewingDressesFileImplement.Models
{
public class Implement : IImplementModel
{
public int Id { get; set; }
public string ImplementFIO { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int WorkExperience { get; set; }
public int Qualification { get; set; }
public static Implement? Create(ImplementBindingModel? model)
{
if (model == null) return null;
return new Implement
{
Id = model.Id,
ImplementFIO = model.ImplementFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification,
};
}
public static Implement? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Implement()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ImplementFIO = element.Element("ImplementFIO")!.Value,
Password = element.Element("Password")!.Value,
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value)
};
}
public XElement GetXElement => new("Implement",
new XAttribute("Id", Id),
new XElement("ImplementFIO", ImplementFIO),
new XElement("Password", Password),
new XElement("Qualification", Qualification.ToString()),
new XElement("WorkExperience", WorkExperience.ToString())
);
public ImplementViewModel GetViewModel => new()
{
Id = Id,
ImplementFIO = ImplementFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
public void Update(ImplementBindingModel model)
{
if (model == null)
{
return;
}
ImplementFIO = model.ImplementFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
}
}