-
Notifications
You must be signed in to change notification settings - Fork 0
/
Domain.fs
43 lines (36 loc) · 1.45 KB
/
Domain.fs
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
namespace Capstone4.Domain
open System
type Customer = {Name: string}
type Account = {AccountId: Guid; Balance: decimal; Owner:Customer}
type CreditAccount = CreditAccount of Account
type RatedAccount =
| InCredit of CreditAccount
| Overdrawn of Account
member this.GetField getter =
match this with
| InCredit (CreditAccount account) -> getter account
| Overdrawn account -> getter account
module Commands =
type BankOperation = Deposit | Withdraw
type Command = AccountCommand of BankOperation | Exit
let tryParseCommand c =
match c with
| 'x' -> Some Exit
| 'w' -> Some (AccountCommand Withdraw)
| 'd' -> Some (AccountCommand Deposit)
| _ -> None
let tryGetBankOperation command =
match command with
| Exit -> None
| AccountCommand op -> Some op
module Transactions =
type Transaction = {Amount : decimal; Action: char; Successful: bool; Timestamp: DateTime}
let serialize transaction =
sprintf "%O***%c***%M***%b"
transaction.Timestamp
transaction.Action
transaction.Amount
transaction.Successful
let deserialize (strTransaction:string) =
let parts = strTransaction.Split([|'*'|],StringSplitOptions.RemoveEmptyEntries)
{Timestamp = DateTime.Parse(parts.[0]);Action = (parts.[1].ToCharArray().[0]); Amount = (Decimal.Parse parts.[2]); Successful = (bool.Parse parts.[3])}