-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.cs
More file actions
52 lines (44 loc) · 1.35 KB
/
Transaction.cs
File metadata and controls
52 lines (44 loc) · 1.35 KB
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
using System;
namespace BankingApp
{
public abstract class Transaction
{
protected decimal _amount;
protected bool _success;
protected bool _executed;
protected bool _reversed;
protected DateTime _dateStamp;
public Transaction(decimal amount)
{
_amount = amount;
}
public bool Success => _success;
public bool Executed => _executed;
public bool Reversed => _reversed;
public DateTime DateStamp => _dateStamp;
public virtual void Print()
{
Console.WriteLine($"Transaction Amount: {_amount:C}");
Console.WriteLine($"Transaction Status: {(_success ? "Successful" : "Failed")}");
Console.WriteLine($"Transaction Date: {_dateStamp}");
}
public virtual void Execute()
{
_executed = true;
_dateStamp = DateTime.Now;
}
public virtual void Rollback()
{
if (!_executed)
{
throw new InvalidOperationException("Transaction has not been executed.");
}
if (_reversed)
{
throw new InvalidOperationException("Transaction has already been reversed.");
}
_reversed = true;
_dateStamp = DateTime.Now;
}
}
}