PIbd-23-Lisov-N.A-SewingDre.../DressAtelierDatabaseImplement/Models/Material.cs

65 lines
1.7 KiB
C#
Raw Normal View History

2023-03-12 16:07:01 +04:00
using DressAtelierContracts.BindingModels;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierDatabaseImplementation.Models
{
public class Material : IMaterialModel
{
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; private set; }
public int ID { get; private set; }
[ForeignKey("MaterialID")]
public virtual List<DressMaterial> DressComponents { get; set; } = new();
public static Material? Create(MaterialBindingModel model)
{
if (model == null)
{
return null;
}
return new Material()
{
ID = model.ID,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Material Create(MaterialViewModel model)
{
return new Material()
{
ID = model.ID,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public void Update(MaterialBindingModel? model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public MaterialViewModel GetViewModel => new()
{
ID = ID,
ComponentName = ComponentName,
Cost = Cost
};
}
}