PIbd-22_Chernyshev_Shabunov.../ComputerShopDatabaseImplement/Models/Component.cs

54 lines
1.2 KiB
C#

using ComputerShopContracts.BindingModels;
using ComputerShopContracts.ViewModels;
using ComputerShopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ComputerShopDatabaseImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
[Required]
public int UserId { get; private set; }
[Required]
public string ComponentName { get; private set; } = string.Empty;
[Required]
public double Cost { get; private set; }
[ForeignKey("ComponentId")]
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
[ForeignKey("ComponentId")]
public virtual List<AssemblyComponent> AssemblyComponents { get; set; } = new();
public static Component Create(ComponentBindingModel Model)
{
return new()
{
Id = Model.Id,
UserId = Model.UserId,
ComponentName = Model.ComponentName,
Cost = Model.Cost,
};
}
public void Update(ComponentBindingModel Model)
{
ComponentName = Model.ComponentName;
Cost = Model.Cost;
}
public ComponentViewModel ViewModel => new()
{
Id = Id,
UserId = UserId,
ComponentName = ComponentName,
Cost = Cost,
};
}
}