2024-05-25 13:06:38 +04:00
|
|
|
|
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; }
|
2024-05-25 17:47:14 +04:00
|
|
|
|
|
|
|
|
|
[ForeignKey("EmployeeID")]
|
2024-05-25 15:04:18 +04:00
|
|
|
|
public int EmployeeID { get; set; }
|
2024-05-25 22:32:22 +04:00
|
|
|
|
|
2024-05-25 13:06:38 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public string Name { get; set; }= string.Empty;
|
2024-05-25 22:32:22 +04:00
|
|
|
|
|
2024-05-25 13:06:38 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Price { get; set; }
|
|
|
|
|
|
2024-05-27 22:05:47 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int CostNum { get; set; }
|
|
|
|
|
|
2024-07-24 09:53:21 +04:00
|
|
|
|
public virtual Employee Employee { get; set; }
|
2024-05-28 12:50:24 +04:00
|
|
|
|
|
2024-05-27 22:05:47 +04:00
|
|
|
|
public static CostItem? Create(CostItemBindingModel? model)
|
2024-05-25 13:06:38 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new CostItem()
|
|
|
|
|
{
|
|
|
|
|
ID = model.ID,
|
2024-05-25 15:04:18 +04:00
|
|
|
|
EmployeeID = model.EmployeeID,
|
2024-05-25 13:06:38 +04:00
|
|
|
|
Name = model.Name,
|
|
|
|
|
Price = model.Price,
|
2024-05-27 22:05:47 +04:00
|
|
|
|
CostNum = model.CostNum,
|
2024-05-25 13:06:38 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2024-05-25 22:32:22 +04:00
|
|
|
|
public void Update(CostItemBindingModel? model)
|
2024-05-25 13:06:38 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-25 15:04:18 +04:00
|
|
|
|
EmployeeID = model.EmployeeID;
|
2024-05-25 13:06:38 +04:00
|
|
|
|
Name = model.Name;
|
|
|
|
|
Price = model.Price;
|
2024-05-27 22:05:47 +04:00
|
|
|
|
CostNum = model.CostNum;
|
2024-05-25 13:06:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CostItemViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
ID = ID,
|
2024-05-25 15:04:18 +04:00
|
|
|
|
EmployeeID = EmployeeID,
|
2024-05-25 13:06:38 +04:00
|
|
|
|
Name = Name,
|
|
|
|
|
Price = Price,
|
2024-05-27 22:05:47 +04:00
|
|
|
|
CostNum = CostNum,
|
2024-05-28 12:50:24 +04:00
|
|
|
|
EmployeeFIO = Employee.EmployeeFIO
|
2024-05-25 13:06:38 +04:00
|
|
|
|
};
|
2024-05-27 22:05:47 +04:00
|
|
|
|
}
|
2024-05-25 13:06:38 +04:00
|
|
|
|
}
|