-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathYucky.cs
More file actions
65 lines (56 loc) · 2.27 KB
/
Copy pathYucky.cs
File metadata and controls
65 lines (56 loc) · 2.27 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
using System;
using System.Collections.Generic;
namespace designIssueExample
{
class Yucky
{
private const int EmployeeIdColumnIndex = 0;
private const int EmployeeNameColumnIndex = 1;
private const int EmployeeAgeColumnIndex = 2;
private const int EmployeeIsSalariedColumnIndex = 3;
public IEnumerable<Employee> GetEmployees(EmployeeFilterType employeeFilterType, string filter, FakeSqlConnection connection)
{
if (employeeFilterType == EmployeeFilterType.ByName && filter == null)
{
throw new ArgumentNullException("filter");
}
string query = "select * from employee, employee_role inner join employee.Id == employee_role.EmployeeId";
List<Employee> result = new List<Employee>();
using (FakeSqlCommand sqlCommand = new FakeSqlCommand(query, connection))
{
FakeSqlDataReader reader;
int retryCount = 5;
while (true)
{
try
{
reader = sqlCommand.ExecuteReader();
break;
}
catch (Exception)
{
if (retryCount-- == 0) throw;
}
}
while (reader.Read())
{
int id = reader.GetInt32(EmployeeIdColumnIndex);
string name = reader.GetString(EmployeeNameColumnIndex);
int age = reader.GetInt32(EmployeeAgeColumnIndex);
bool isSalaried = reader.GetBoolean(EmployeeIsSalariedColumnIndex);
switch (employeeFilterType)
{
case EmployeeFilterType.ByName:
if (!name.StartsWith(filter)) continue;
break;
case EmployeeFilterType.ExemptOnly:
if (age < 40 || !isSalaried) continue;
break;
}
result.Add(new Employee {Name = name, Id = id, Age = age, IsSalaried = isSalaried});
}
}
return result;
}
}
}