-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaxtonUserRepository.cs
More file actions
109 lines (96 loc) · 2.29 KB
/
Copy pathPaxtonUserRepository.cs
File metadata and controls
109 lines (96 loc) · 2.29 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
using System;
using System.Collections.Generic;
using System.Linq;
using Paxton.Net2.OemClientLibrary;
namespace PaxtonSync
{
internal class PaxtonUserRepository
{
private readonly PaxtonClient _net2Client;
private readonly bool _trialRunOnly;
public PaxtonUserRepository(PaxtonClient net2Client, bool trialRunOnly)
{
_net2Client = net2Client;
_trialRunOnly = trialRunOnly;
}
public IReadOnlyCollection<PaxtonUser> GetAllUsers()
{
var allUsers = from pair in _net2Client.ViewUserRecords().UsersList()
let user = pair.Value
select new PaxtonUser(user);
return allUsers.ToArray();
}
public void UpdateUser(PaxtonUser paxtonUser)
{
if (_trialRunOnly)
{
Logger.WriteLine("{0}\tTrial run - not updating user.", paxtonUser);
return;
}
_UpdatePaxtonUser(paxtonUser, true);
}
private void _UpdatePaxtonUser(PaxtonUser paxtonUser, bool active)
{
_net2Client.UpdateUserRecord(
paxtonUser.UserId,
paxtonUser.AccessLevelId,
paxtonUser.DepartmentId,
paxtonUser.AntiPassbackUser,
paxtonUser.AlarmUser,
paxtonUser.FirstName,
paxtonUser.MiddleName,
paxtonUser.Surname,
paxtonUser.Telephone,
paxtonUser.Extension,
paxtonUser.PIN,
paxtonUser.Picture,
paxtonUser.ActivationDate,
active, //if we're updating a use we want to make sure it's also active instead of just copying paxtonUser.Active,
paxtonUser.Fax,
paxtonUser.ExpiryDate,
paxtonUser.CustomFields);
}
public void CreateUser(int accessLevelId, string firstName, string surname, int becNumber)
{
if (_trialRunOnly)
{
Logger.WriteLine("{0} {1}\tTrial run - not adding user.", firstName, surname);
return;
}
var CustomFields = new string[]
{
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
becNumber.ToString()
};
const int departmentId = 0;
_net2Client.AddUserRecord(
accessLevelId,
departmentId,
firstName,
surname,
CustomFields);
}
public void DeleteUser(PaxtonUser paxtonUser)
{
if (_trialRunOnly)
{
Logger.WriteLine("{0}\tTrial run - not deleting user.", paxtonUser);
return;
}
_UpdatePaxtonUser(paxtonUser, false);
}
}
}