CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs
Илья Федотов 83a2cfe0d7 fix bugs
2024-07-24 09:53:21 +04:00

70 lines
1.8 KiB
C#

using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class CostItem : ICostItemModel
{
public int ID { get; set; }
[ForeignKey("EmployeeID")]
public int EmployeeID { get; set; }
[Required]
public string Name { get; set; }= string.Empty;
[Required]
public double Price { get; set; }
[Required]
public int CostNum { get; set; }
public virtual Employee Employee { get; set; }
public static CostItem? Create(CostItemBindingModel? model)
{
if (model == null)
{
return null;
}
return new CostItem()
{
ID = model.ID,
EmployeeID = model.EmployeeID,
Name = model.Name,
Price = model.Price,
CostNum = model.CostNum,
};
}
public void Update(CostItemBindingModel? model)
{
if (model == null)
{
return;
}
EmployeeID = model.EmployeeID;
Name = model.Name;
Price = model.Price;
CostNum = model.CostNum;
}
public CostItemViewModel GetViewModel => new()
{
ID = ID,
EmployeeID = EmployeeID,
Name = Name,
Price = Price,
CostNum = CostNum,
EmployeeFIO = Employee.EmployeeFIO
};
}
}