Coursach/Course/DatabaseImplement/Models/Detail.cs

62 lines
1.3 KiB
C#
Raw Normal View History

2024-04-21 20:36:07 +04:00
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();
2024-04-23 22:34:09 +04:00
[ForeignKey("DetailId")]
public virtual List<DetailProduction> DetailProductions { get; set; } = new();
2024-04-21 20:36:07 +04:00
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
};
}
}