Coursach/Course/DatabaseImplement/Models/Detail.cs

62 lines
1.3 KiB
C#

using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DatabaseImplement.Models
{
public class Detail : IDetailModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public double Cost { get; set; }
[Required]
public int UserId { get; set; }
[ForeignKey("DetailId")]
public virtual List<DetailProduct> DetailProducts { get; set; } = new();
[ForeignKey("DetailId")]
public virtual List<DetailProduction> DetailProductions { get; set; } = new();
public static Detail? Create(DetailBindingModel model)
{
if (model == null)
{
return null;
}
return new Detail
{
Id = model.Id,
Name = model.Name,
Cost = model.Cost,
UserId = model.UserId
};
}
public static Detail Create(DetailViewModel model)
{
return new Detail
{
Id = model.Id,
Name = model.Name,
Cost = model.Cost,
UserId = model.UserId
};
}
public void Update(DetailBindingModel model)
{
if (model == null)
return;
Name = model.Name;
Cost = model.Cost;
}
public DetailViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Cost = Cost,
UserId = UserId
};
}
}