Coursach/Course/DatabaseImplement/Models/Detail.cs

68 lines
1.5 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]
2024-04-30 22:27:52 +04:00
public DateTime DateCreate { get; set; } = DateTime.Now;
[Required]
2024-04-21 20:36:07 +04:00
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-24 12:35:17 +04:00
public virtual Implementer User { get; set; }
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,
2024-04-30 22:27:52 +04:00
UserId = model.UserId,
DateCreate = model.DateCreate
2024-04-21 20:36:07 +04:00
};
}
public static Detail Create(DetailViewModel model)
{
return new Detail
{
Id = model.Id,
Name = model.Name,
Cost = model.Cost,
2024-04-30 22:27:52 +04:00
UserId = model.UserId,
DateCreate = model.DateCreate
2024-04-21 20:36:07 +04:00
};
}
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,
2024-04-30 22:27:52 +04:00
UserId = UserId,
DateCreate = DateCreate
2024-04-21 20:36:07 +04:00
};
}
}