SUBD_SushiBar/SushiBar/SushiBarDatabaseImplement/Models/Menu.cs

58 lines
1.5 KiB
C#
Raw Normal View History

using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.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;
namespace SushiBarDatabaseImplement.Models
{
public class Menu : IMenuModel
{
public int Id { get; set; }
[Required]
public string FoodName { get; set; } = string.Empty;
[Required]
public string Description { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
[ForeignKey("MenuId")]
public virtual List<TaskMenu> TaskMenus { get; set; } = new();
public static Menu? Create(MenuBindingModel model)
{
if (model == null) return null;
return new Menu()
{
Id = model.Id,
FoodName = model.FoodName,
Description = model.Description,
Price = model.Price
};
}
public void Update(MenuBindingModel model)
{
if (model == null) return;
Id = model.Id;
FoodName = model.FoodName;
Description = model.Description;
Price = model.Price;
}
public MenuViewModel GetViewModel => new()
{
Id = Id,
FoodName = FoodName,
Description = Description,
Price = Price
};
}
}