64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using ComputerStoreContracts.BindingModels;
|
|
using ComputerStoreContracts.ViewModels;
|
|
using ComputerStoreDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ComputerStoreDatabaseImplement.Models
|
|
{
|
|
public class Component : IComponentModel
|
|
{
|
|
public int ID { get; private set; }
|
|
|
|
[Required]
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
[Required]
|
|
public double Price { get; private set; }
|
|
|
|
[ForeignKey("ComponentID")]
|
|
public virtual List<ProductComponent> ConsignmentComponents { get; private set; } = new();
|
|
|
|
[ForeignKey("ComponentID")]
|
|
public virtual List<RequestComponent> RequestComponents { get; private set; } = new();
|
|
|
|
public static Component? Create(ComponentBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Component()
|
|
{
|
|
ID = model.ID,
|
|
Name = model.Name,
|
|
Price = model.Price
|
|
};
|
|
}
|
|
|
|
public void Update(ComponentBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Name = model.Name;
|
|
Price = model.Price;
|
|
}
|
|
public ComponentViewModel GetViewModel => new()
|
|
{
|
|
ID = ID,
|
|
Name = Name,
|
|
Price = Price
|
|
};
|
|
|
|
|
|
}
|
|
}
|