51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
|
using ComputerHardwareStoreContracts.BindingModels;
|
|||
|
using ComputerHardwareStoreContracts.ViewModels;
|
|||
|
using ComputerHardwareStoreDataModels.Models;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
|
|||
|
namespace ComputerHardwareStoreDatabaseImplement.Models
|
|||
|
{
|
|||
|
public class Component : IComponentModel
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
[Required]
|
|||
|
public string Name { get; private set; } = string.Empty;
|
|||
|
[Required]
|
|||
|
public double Cost { get; set; }
|
|||
|
[ForeignKey("ComponentId")]
|
|||
|
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
|
|||
|
public static Component? Create(ComponentBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Component()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Name = model.Name,
|
|||
|
Cost = model.Cost
|
|||
|
};
|
|||
|
}
|
|||
|
public void Update (ComponentBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
|||
|
Cost = model.Cost;
|
|||
|
}
|
|||
|
|
|||
|
public ComponentViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
Name = Name,
|
|||
|
Cost = Cost
|
|||
|
};
|
|||
|
|
|||
|
public int StoreKeeperId => throw new NotImplementedException();
|
|||
|
}
|
|||
|
}
|