2023-04-06 17:00:40 +04:00
|
|
|
|
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")]
|
2023-04-07 20:03:44 +04:00
|
|
|
|
public virtual List<ProductComponent> ConsignmentComponents { get; private set; } = new();
|
2023-04-06 17:00:40 +04:00
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|