CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs

64 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
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 Product : IProductModel
{
public int ID { get; set; }
[Required]
public string ProductName { get; set; }=string.Empty;
[Required]
public double Price { get; set; }
[ForeignKey("CostItemID")]
public int CostItemID { get; set; }
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
public static Product? Create(ProductBindingModel? model)
{
if (model == null)
{
return null;
}
return new Product()
{
ID = model.ID,
ProductName = model.ProductName,
Price = model.Price,
CostItemID=model.CostItemID,
PayOption=model.PayOption
};
}
public void Update(ProductBindingModel model)
{
if (model == null)
{
return;
}
ID = model.ID;
ProductName = model.ProductName;
Price = model.Price;
CostItemID = model.CostItemID;
PayOption = model.PayOption;
}
public ProductViewModel GetViewModel => new()
{
ID = ID,
ProductName = ProductName,
Price = Price,
CostItemID = CostItemID,
PayOption = PayOption
};
}
}