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

84 lines
2.2 KiB
C#
Raw Permalink Normal View History

2024-05-26 13:40:22 +04:00
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
2024-06-22 21:11:56 +04:00
using System.Runtime.Serialization;
2024-05-26 13:40:22 +04:00
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SewingDressesFileImplement.Models
{
2024-06-22 21:11:56 +04:00
[DataContract]
2024-05-26 13:40:22 +04:00
public class Implement : IImplementModel
{
2024-06-22 21:11:56 +04:00
[DataMember]
2024-05-26 13:40:22 +04:00
public int Id { get; set; }
2024-06-22 21:11:56 +04:00
[DataMember]
2024-05-26 13:40:22 +04:00
public string ImplementFIO { get; set; } = string.Empty;
2024-06-22 21:11:56 +04:00
[DataMember]
2024-05-26 13:40:22 +04:00
public string Password { get; set; } = string.Empty;
2024-06-22 21:11:56 +04:00
[DataMember]
2024-05-26 13:40:22 +04:00
public int WorkExperience { get; set; }
2024-06-22 21:11:56 +04:00
[DataMember]
2024-05-26 13:40:22 +04:00
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;
}
}
}