-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQuestion1.cs
95 lines (75 loc) · 2.97 KB
/
Question1.cs
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
using System;
using System.Linq;
using System.Threading.Tasks;
using Example.Interview.Question.Placeholders;
using Unity;
namespace csharp_interview
{
/// <summary>
/// Person service
/// </summary>
public class Question1 : BaseService, IPersonService
{
private readonly IAuthenticatedUser _authenticatedUser;
private readonly Lazy<IConfigurationRepository> _configurationRepository;
private readonly Lazy<IPositionService> _positionService;
private readonly IUnityContainer _container;
public Question1(
IAuthenticatedUser authenticatedUser,
Lazy<IConfigurationRepository> configurationRepository,
Lazy<IPositionService> positionService,
IUnityContainer container
)
{
_authenticatedUser = authenticatedUser;
_configurationRepository = configurationRepository;
_positionService = positionService;
_container = container;
}
public async Task<PersonModel> GetPerson(Guid id)
{
IPersonRepository personRepository = _container.Resolve<IPersonRepository>();
var configurationItems = _configurationRepository.Value.GetConfigurationForPerson(id);
var configuration = configurationItems.First();
if (!configuration.IsPersonAccessible)
{
return null;
}
var personEntity = personRepository.Get(id);
var personModel = new PersonModel
{
FirstName = personEntity.FirstName,
LastName = personEntity.LastName
};
return personModel;
}
/// <summary>
/// Load a person that has a name matching given personName
/// </summary>
/// <param name="personName">FirstName or LastName of the Person to find</param>
/// <returns>PersonModel matching the given personName</returns>
public async Task<PersonModel> GetPerson(string personName)
{
var personRepository = _container.Resolve<IPersonRepository>();
var personEntity = await personRepository.Find(personName);
var configurationItems = _configurationRepository.Value.GetConfigurationForPerson(personEntity.Id);
var configuration = configurationItems.First();
if (!configuration.IsPersonAccessible)
{
return null;
}
var personModel = new PersonModel
{
FirstName = personEntity.FirstName,
LastName = personEntity.LastName
};
return personModel;
}
public async Task<PersonModel> GetLastRecordEditor(string personName)
{
var personRepository = _container.Resolve<IPersonRepository>();
var editorName = await personRepository.FindEditorName(personName);
return await GetPerson(editorName);
}
}
}