PIbd-21_Medvedkov_Coursach/ComputerShopDatabaseImplement/Models/Component.cs
2024-05-01 04:42:57 +04:00

57 lines
1.3 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 double Cost { get; private set; }
[Required]
public string ComponentName { get; private set; } = string.Empty;
[Required]
public string Description { get; private set; } = string.Empty;
[Required]
public int UserId { get; private set; }
[ForeignKey("ComponentId")]
public virtual List<AssemblyComponent> AssemblyComponents { get; set; } = new();
public static Component Create(ComponentBindingModel Model)
{
return new()
{
Id = Model.Id,
Cost = Model.Cost,
ComponentName = Model.ComponentName,
UserId = Model.UserId,
};
}
public void Update(ComponentBindingModel Model)
{
Cost = Model.Cost;
ComponentName = Model.ComponentName;
}
public ComponentViewModel ViewModel => new()
{
Id = Id,
Cost = Cost,
ComponentName = ComponentName,
UserId = UserId,
};
}
}