public class Product
{
public int Id { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public int PercentDiscount { get; set; }
public ProductDto ToProductDto()
{
return new ProductDto
{
Name = ProductName,
SalePrice = UnitPrice - UnitPrice * PercentDiscount / 100
};
}
public static implicit operator ProductDto(Product product)
{
return new ProductDto
{
Name = product.ProductName,
SalePrice = product.UnitPrice - product.UnitPrice * product.PercentDiscount / 100
};
}
}
public class ProductDto
{
public string Name { get; set; }
public decimal SalePrice { get; set; }
public static ProductDto FromProduct(Product product)
{
return new ProductDto
{
Name = product.ProductName,
SalePrice = product.UnitPrice - product.UnitPrice * product.PercentDiscount / 100
};
}
public static explicit operator ProductDto(Product product)
{
return new ProductDto
{
Name = product.ProductName,
SalePrice = product.UnitPrice - product.UnitPrice * product.PercentDiscount / 100
};
}
}