CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs
Илья Федотов f9c768037d is done
2024-04-29 23:20:48 +04:00

67 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.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; }
[Required]
public int CategoryID { get; set; }
public static Product? Create(ProductBindingModel? model)
{
if (model == null)
{
return null;
}
return new Product()
{
ID = model.ID,
ProductName = model.ProductName,
Price = model.Price,
CategoryID = model.CategoryID
};
}
public static Product? Create(ProductViewModel model)
{
return new Product
{
ID = model.ID,
ProductName = model.ProductName,
Price = model.Price,
CategoryID = model.CategoryID
};
}
public void Update(ProductBindingModel model)
{
if (model == null)
{
return;
}
ProductName = model.ProductName;
Price = model.Price;
CategoryID = model.CategoryID;
}
public ProductViewModel GetViewModel => new()
{
ID = ID,
ProductName = ProductName,
Price = Price,
CategoryID = CategoryID
};
}
}