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
|
|
|
|
|
{
|
2024-03-15 14:49:38 +04:00
|
|
|
|
public string ComponentName { get; set; } = string.Empty;
|
2024-03-02 10:45:04 +04:00
|
|
|
|
|
|
|
|
|
public double Price { get; set; }
|
|
|
|
|
|
2024-03-15 14:49:38 +04:00
|
|
|
|
public int ID { get; set; }
|
2024-03-02 10:45:04 +04:00
|
|
|
|
|
|
|
|
|
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),
|
2024-03-15 14:49:38 +04:00
|
|
|
|
new XElement("ComponentName", ComponentName),
|
2024-03-02 10:45:04 +04:00
|
|
|
|
new XElement("Price", Price.ToString()));
|
|
|
|
|
}
|
|
|
|
|
}
|