58 lines
1.8 KiB
C#
Raw Normal View History

2024-03-02 10:45:04 +04:00
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
{
internal class Food : IFoodModel
{
public string ComponentName { get; private set; } = string.Empty;
public double Price { get; set; }
public int ID { get; private set; }
public static Food? Create(FoodBindingModel? model)
{
if (model == null) return null;
return new Food()
{
ID = model.ID,
ComponentName = model.ComponentName,
Price = model.Price,
};
}
public static Food? Create(XElement element) {
if (element == null) return null;
return new Food()
{
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value)
};
}
public void Update(FoodBindingModel? model)
{
if (model == null) return;
ComponentName = model.ComponentName;
Price = model.Price;
}
public FoodViewModel GetViewModel => new()
{
ID = ID,
ComponentName = ComponentName,
Price = Price,
};
public XElement GetXElement => new("Food", new XAttribute("ID", ID),
new XElement("CompoenntName", ComponentName),
new XElement("Price", Price.ToString()));
}
}