PIbd-23_Leonteva_V._A._LawFirm/LawFirm/LawFirmDatabaseImplement/Models/Blank.cs

56 lines
1.5 KiB
C#
Raw Normal View History

2024-04-23 12:07:00 +04:00
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace LawFirmDatabaseImplement.Models
{
public class Blank : IBlankModel
{
public int Id { get; private set; }
[Required]
public string BlankName { get; private set; } = string.Empty;
[Required]
public double Price { get; set; }
[ForeignKey("BlankId")]
public virtual List<DocumentBlank> DocumentBlanks { get; set; } = new();
public static Blank? Create(BlankBindingModel model)
{
if (model == null)
{
return null;
}
return new Blank()
{
Id = model.Id,
BlankName = model.BlankName,
Price = model.Price
};
}
public static Blank Create(BlankViewModel model)
{
return new Blank
{
Id = model.Id,
BlankName = model.BlankName,
Price = model.Price
};
}
public void Update(BlankBindingModel model)
{
if (model == null)
{
return;
}
BlankName = model.BlankName;
Price = model.Price;
}
public BlankViewModel GetViewModel => new()
{
Id = Id,
BlankName = BlankName,
Price = Price
};
}
}