61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using AccountingWarehouseProductsContracts.BindingModels;
|
|
using AccountingWarehouseProductsContracts.ViewModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
|
{
|
|
public class Product
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
[Required]
|
|
public string ProductName { get; set; } = string.Empty;
|
|
|
|
[Required]
|
|
public double Cost { get; set; }
|
|
|
|
[Required]
|
|
public DateTime? ExpirationDate { get; set; }
|
|
|
|
[Required]
|
|
public string Category { get; set; } = string.Empty;
|
|
|
|
public static Product? Create(ProductBindingModel model)
|
|
{
|
|
if (model == null) return null;
|
|
|
|
return new Product()
|
|
{
|
|
Id = model.Id,
|
|
ProductName = model.ProductName,
|
|
Cost = model.Cost,
|
|
ExpirationDate = model.ExpirationDate,
|
|
Category = model.Category
|
|
};
|
|
}
|
|
|
|
public void Update(ProductBindingModel model)
|
|
{
|
|
if (model == null) return;
|
|
ProductName = model.ProductName;
|
|
Cost = model.Cost;
|
|
ExpirationDate = model.ExpirationDate;
|
|
Category = model.Category;
|
|
}
|
|
|
|
public ProductViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
ProductName = ProductName,
|
|
Cost = Cost,
|
|
ExpirationDate = ExpirationDate,
|
|
Category = Category
|
|
};
|
|
}
|
|
}
|