summaryrefslogtreecommitdiff
path: root/DesignPatterns/src/app/DesignPatterns.State/ProcessingTransactionState.cs
blob: f91cae4d9b4f408e9cd8d6fbfbf591253c0bb2b4 (plain)
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
using System;

namespace DesignPatterns.State {
	internal class ProcessingTransactionState : IState {
		public ProcessingTransactionState( IPosTerminal terminal ) {
			_terminal = terminal;
		}

		public void ProcessTransaction( ) {
			if ( (++_counter % 5) == 0 ) {
				_terminal.CurrentState = new TransactionRejectedState( _terminal );
			}
			else {
				_terminal.CurrentState = new TransactionApprovedState( _terminal );
			}
		}

		public void PrintReceipt( ) {
			Console.Out.WriteLine( "The transaction needs to be processed first" );
		}

		public void SwipeCard( string cardNumber ) {
			Console.Out.WriteLine( "You have already swiped a card" );
		}

		public void EnterAmount( double amount ) {
			Console.Out.WriteLine( "You have already entered an amount" );
		}

		public void EnterPin( string pin ) {
			Console.Out.WriteLine( "You have already entered a PIN" );
		}

		private readonly IPosTerminal _terminal;
		private static int _counter;
	}
}