61 lines
1.5 KiB
C#
Raw Normal View History

2023-02-27 17:07:02 +04:00
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
2023-05-04 16:39:59 +04:00
using System.Runtime.Serialization;
2023-02-27 17:07:02 +04:00
2023-05-04 16:39:59 +04:00
namespace SushiBarDatabaseImplement.Models;
[DataContract]
public class Component : IComponentModel
2023-02-27 17:07:02 +04:00
{
2023-05-04 16:39:59 +04:00
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public string ComponentName { get; private set; } = string.Empty;
[Required]
[DataMember]
public double Cost { get; set; }
[ForeignKey("ComponentId")]
public virtual List<SushiComponent> SushiComponent { get; set; } = new();
public static Component? Create(ComponentBindingModel model)
2023-02-27 17:07:02 +04:00
{
2023-05-04 16:39:59 +04:00
if (model == null)
2023-02-27 17:07:02 +04:00
{
2023-05-04 16:39:59 +04:00
return null;
2023-02-27 17:07:02 +04:00
}
2023-05-04 16:39:59 +04:00
return new Component()
2023-02-27 17:07:02 +04:00
{
2023-05-04 16:39:59 +04:00
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Component Create(ComponentViewModel model)
{
return new Component
2023-02-27 17:07:02 +04:00
{
2023-05-04 16:39:59 +04:00
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
2023-02-27 17:07:02 +04:00
};
}
2023-05-04 16:39:59 +04:00
public void Update(ComponentBindingModel model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
}