-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProduct.cs
101 lines (77 loc) · 2.26 KB
/
Product.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
namespace CSharpFundamentals
{
public class Product {
public Product() {
Init();
}
// Create constructor
public Product(int id, string name) {
ProductId = id;
Name = name;
Init();
}
public void Init()
{
Color = DEFAULT_COLOR;
StandarCost = 1.00M;
ListPrice = 5.00M;
SellStartDate = DateTime.Now;
}
// Hardcode
private const string DEFAULT_COLOR = "Blue";
public int ProductId { get; set; }
public string Name { get; set; }
public string Color { get; set; }
private decimal _StandarCost;
public decimal StandarCost
{
get { return _StandarCost; }
set { _StandarCost = value; CalculateProfit(); }
}
private decimal _ListPrice;
public decimal ListPrice
{
get { return _ListPrice; }
set { _ListPrice = value; CalculateProfit(); }
}
private decimal _Profit;
public decimal Profit {
get { return _Profit; }
}
public DateTime SellStartDate { get; set; }
public DateTime SellEndDate { get; set; }
private void CalculateProfit()
{
_Profit = _ListPrice - _StandarCost;
}
public int GetNumberOfSellDays()
{
return (SellEndDate - SellStartDate).Days;
}
public decimal CalculateProfit(decimal price, decimal? cost = 1)
{
return price - cost ?? 1;
}
public decimal CalculateProfitByValue(decimal price, decimal cost)
{
price = 20;
cost = 5;
return price - cost;
}
public decimal CalculateProfitByRef(ref decimal price, ref decimal cost)
{
price = 20;
cost = 5;
return price - cost;
}
public void TrialIncreaseByPercentage(decimal percent, out decimal price, out decimal cost)
{
// must init out params
price = ListPrice;
cost = StandarCost;
// set ke manapun kau suka
price *= percent;
cost *= percent;
}
}
}