89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
using AccountingWarehouseProductsContracts.BindingModels;
|
|
using AccountingWarehouseProductsContracts.ViewModels;
|
|
using AccountingWarehouseProductsDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
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 DateofFabrication { get; set; }
|
|
|
|
[Required]
|
|
public DateTime? ValidUntil { get; set; }
|
|
|
|
[Required]
|
|
public string Category { get; set; } = string.Empty;
|
|
|
|
[ForeignKey("ProductId")]
|
|
public virtual List<OrderProduct> OrderProduct { get; set; } = new();
|
|
|
|
[ForeignKey("ProductId")]
|
|
public virtual List<Order> Orders { get; set; } = new();
|
|
|
|
public static Product? Create(ProductBindingModel model)
|
|
{
|
|
if (model == null) return null;
|
|
|
|
return new Product()
|
|
{
|
|
Id = model.Id,
|
|
ProductName = model.ProductName,
|
|
Cost = model.Cost,
|
|
DateofFabrication = model.DateofFabrication,
|
|
ValidUntil = model.ValidUntil,
|
|
Category = model.Category
|
|
};
|
|
}
|
|
|
|
public static Product Create(ProductViewModel model)
|
|
{
|
|
return new Product
|
|
{
|
|
Id = model.Id,
|
|
ProductName = model.ProductName,
|
|
Cost = model.Cost,
|
|
DateofFabrication = model.DateofFabrication,
|
|
ValidUntil = model.ValidUntil,
|
|
Category = model.Category
|
|
};
|
|
}
|
|
|
|
public void Update(ProductBindingModel model)
|
|
{
|
|
if (model == null) return;
|
|
ProductName = model.ProductName;
|
|
Cost = model.Cost;
|
|
DateofFabrication = model.DateofFabrication;
|
|
ValidUntil = model.ValidUntil;
|
|
Category = model.Category;
|
|
}
|
|
|
|
public ProductViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
ProductName = ProductName,
|
|
Cost = Cost,
|
|
DateofFabrication = DateofFabrication,
|
|
ValidUntil = ValidUntil,
|
|
Category = Category
|
|
};
|
|
}
|
|
}
|