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; set; } = string.Empty; public double Price { get; set; } public int ID { get; 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("ProductName")!.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("ProductName", ComponentName), new XElement("Price", Price.ToString())); } }