forked from trashvin/Tutorial_UsingStateless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
196 lines (163 loc) · 5.46 KB
/
Copy pathProgram.cs
File metadata and controls
196 lines (163 loc) · 5.46 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.Reflection;
using static System.Console;
using System.Collections.Generic;
using System.Text;
namespace AssetWorkflow
{
class Program
{
private static List<Asset> assetList = new List<Asset>();
public static int counter = 1;
static void Main()
{
int choice =0;
while ( choice != 4)
{
choice = ShowMainMenu();
switch (choice)
{
case 1:
WriteLine("Creating asset..");
CreateAsset();
break;
case 2:
WriteLine("Managing assets...");
ManageAssets();
break;
case 3:
WriteLine("Listing assets...");
ListAssets();
break;
case 4:
WriteLine("Exiting.....");
break;
default:
break;
}
}
}
private static void CreateAsset()
{
AssetInformation assInfo = new AssetInformation(counter);
counter++;
assInfo.AssetName = "Asset " + assInfo.AssetID.ToString();
Asset tempAsset = new Asset(assInfo);
assetList.Add(tempAsset);
}
private static void ListAssets()
{
foreach(Asset asset in assetList)
{
StringBuilder data = new StringBuilder();
data.Append(asset.AssetData.AssetID.ToString() + " : ");
data.Append(asset.AssetData.AssetName + " : ");
if (asset.AssetData.Owner != null)
{
data.Append(asset.AssetData.Owner.EmailAddress + " : ");
}
data.Append(asset.AssetState.ToString());
WriteLine(data.ToString());
}
}
private static int ShowMainMenu()
{
int choice = 0;
WriteLine("Asset Manager v1");
do
{
WriteLine("Menu : (1) Create Asset (2) Manage Asset (3) List Assets (4)Exit");
string ch = ReadLine();
Int32.TryParse(ch,out choice);
} while (choice < 1 || choice > 4);
return choice;
}
private static void ManageAssets()
{
string assetID;
ListAssets();
WriteLine("Select asset to manage.");
Write("Asset ID :");
assetID = ReadLine();
string valid = "ABCDEFGHIJK";
if (IsAssetExist(assetID))
{
string choice = "X";
WriteLine("Asset Management");
do
{
WriteLine("Menu : (A) Test (B) Assign (C) Repair (D) Upgrade (E) Release (F) Transfer (G) Repaired (H) Discard (I) Lost (J) Found (K) Exit");
choice = ReadLine().ToUpper();
} while (!valid.Contains(choice));
Asset asset = assetList.Find(i => i.AssetData.AssetID.ToString() == assetID);
if ( choice == "K")
{
WriteLine("Exiting asset management.");
Console.WriteLine(asset.GetDOTGraph());
}
else
{
ManageAsset(asset, choice);
}
}
else
{
WriteLine("Asset not found.");
}
}
private static void ManageAsset(Asset asset,string action)
{
switch(action)
{
case "A":
asset.FinishedTesting();
break;
case "B":
asset.Assign(GetOwner());
break;
case "C":
asset.RequestRepair();
break;
case "D":
asset.RequestUpdate();
break;
case "E":
asset.Release();
break;
case "F":
asset.Transfer(GetOwner());
break;
case "G":
asset.Repaired();
break;
case "H":
asset.Discard();
break;
case "I":
asset.Lost();
break;
case "J":
asset.Found();
break;
default:
break;
}
WriteLine($"Success : {asset.IsSuccessful().ToString()}");
}
private static Person GetOwner()
{
int id = counter;
Console.WriteLine("Enter name : ");
string name = Console.ReadLine();
string email = name.Replace(" ", "") + "@email.com";
counter++;
return new Person(id, name, email);
}
private static bool IsAssetExist(string assetID)
{
int id = 0;
Int32.TryParse(assetID,out id);
return assetList.Exists(i => i.AssetData.AssetID == id);
}
}
}