PIbd-23_Nevaeva_K.A._Travel.../TravelCompany/TravelCompanyFileImplement/Models/Condition.cs
2023-03-06 09:07:54 +04:00

67 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TravelCompanyDataModels.Models;
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.ViewModels;
using System.Xml.Linq;
namespace TravelCompanyFileImplement.Models
{
public class Condition : IConditionModel
{
public int Id { get; private set; }
public string ConditionName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static Condition? Create(ConditionBindingModel model)
{
if (model == null)
{
return null;
}
return new Condition()
{
Id = model.Id,
ConditionName = model.ConditionName,
Cost = model.Cost
};
}
public static Condition? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Condition()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ConditionName = element.Element("ConditionName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
public void Update(ConditionBindingModel model)
{
if (model == null)
{
return;
}
ConditionName = model.ConditionName;
Cost = model.Cost;
}
public ConditionViewModel GetViewModel => new()
{
Id = Id,
ConditionName = ConditionName,
Cost = Cost
};
public XElement GetXElement => new("Condition",
new XAttribute("Id", Id),
new XElement("ConditionName", ConditionName),
new XElement("Cost", Cost.ToString()));
}
}