2024-04-29 01:55:20 +04:00
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
2024-05-25 13:06:38 +04:00
|
|
|
|
using ElectronicsShopDataModels.Enums;
|
2024-04-29 01:55:20 +04:00
|
|
|
|
using ElectronicsShopDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-04-30 21:59:22 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-04-29 01:55:20 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopDataBaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Product : IProductModel
|
|
|
|
|
{
|
|
|
|
|
public int ID { get; set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public string ProductName { get; set; }=string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public double Price { get; set; }
|
2024-05-25 13:06:38 +04:00
|
|
|
|
[ForeignKey("CostItemID")]
|
|
|
|
|
public int CostItemID { get; set; }
|
|
|
|
|
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
|
2024-04-29 01:55:20 +04:00
|
|
|
|
|
|
|
|
|
public static Product? Create(ProductBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Product()
|
|
|
|
|
{
|
|
|
|
|
ID = model.ID,
|
|
|
|
|
ProductName = model.ProductName,
|
|
|
|
|
Price = model.Price,
|
2024-05-25 13:06:38 +04:00
|
|
|
|
CostItemID=model.CostItemID,
|
|
|
|
|
PayOption=model.PayOption
|
2024-04-29 01:55:20 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(ProductBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-25 13:06:38 +04:00
|
|
|
|
ID = model.ID;
|
2024-04-29 01:55:20 +04:00
|
|
|
|
ProductName = model.ProductName;
|
|
|
|
|
Price = model.Price;
|
2024-05-25 13:06:38 +04:00
|
|
|
|
CostItemID = model.CostItemID;
|
|
|
|
|
PayOption = model.PayOption;
|
2024-04-29 01:55:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProductViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
ID = ID,
|
|
|
|
|
ProductName = ProductName,
|
|
|
|
|
Price = Price,
|
2024-05-25 13:06:38 +04:00
|
|
|
|
CostItemID = CostItemID,
|
|
|
|
|
PayOption = PayOption
|
2024-04-29 01:55:20 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|