61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using DinerContracts.BindingModels;
|
|
using DinerContracts.ViewModels;
|
|
using DinerDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
|
|
namespace DinerDataBaseImplement.Models
|
|
{
|
|
public class Food : IFoodModel
|
|
{
|
|
[Required]
|
|
public string ComponentName { get; set; } = string.Empty;
|
|
|
|
[Required]
|
|
public double Price { get; set; }
|
|
|
|
public int ID { get; set; }
|
|
|
|
[ForeignKey("ComponentID")]
|
|
public virtual List<SnackFood> SnackFood { get; set;} = new();
|
|
|
|
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(FoodViewModel model)
|
|
{
|
|
return new Food
|
|
{
|
|
ID = model.ID,
|
|
ComponentName = model.ComponentName,
|
|
Price = model.Price,
|
|
};
|
|
}
|
|
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,
|
|
};
|
|
}
|
|
}
|