This repository was archived by the owner on Apr 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPersonAPI.cs
More file actions
202 lines (174 loc) · 9.27 KB
/
PersonAPI.cs
File metadata and controls
202 lines (174 loc) · 9.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
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
197
198
199
200
201
202
using System;
using System.Collections.Generic;
using System.Configuration;
using System.ServiceModel.Web;
using Arena.Core;
using Arena.Security;
using Arena.SmallGroup;
namespace Arena.Custom.HDC.WebService
{
class PersonAPI
{
/// <summary>
/// <b>GET person/{id}/relationships</b>
///
/// Retrieve a list of all person relationships for the given person ID.
/// \since 1.0.0
/// </summary>
/// <returns>List of PersonRelationship objects.</returns>
[WebGet(UriTemplate = "person/{id}/relationships")]
public Contracts.GenericListResult<Contracts.PersonRelationship> GetPersonRelationships(int id)
{
Contracts.GenericListResult<Contracts.PersonRelationship> list = new Contracts.GenericListResult<Contracts.PersonRelationship>();
Contracts.PersonRelationshipMapper mapper = new Contracts.PersonRelationshipMapper();
RelationshipCollection relationships = new RelationshipCollection(id);
list.Items = new List<Contracts.PersonRelationship>();
list.Total = relationships.Count;
list.Max = list.Total;
list.Start = 0;
foreach (Relationship relationship in relationships)
{
list.Items.Add(mapper.FromArena(relationship));
}
return list;
}
/// <summary>
/// Retrieve a list of all small group membership for the person.
/// Security is taken into consideration, so if the logged in user does not
/// have permission to see the group, it will not be returned.
/// </summary>
/// <param name="id">The ID number of the person to retrieve membership of.</param>
/// <param name="start">The start index to begin retrieving records at.</param>
/// <param name="max">The maximum number of records to retrieve.</param>
/// <returns>GenericListResult of SmallGroupMember objects.</returns>
[WebGet(UriTemplate = "person/{id}/groupmembership/list?start={start}&max={max}")]
public Contracts.GenericListResult<Contracts.SmallGroupMember> GetPersonSmallGroupMembership(int id, int start, int max)
{
Contracts.GenericListResult<Contracts.SmallGroupMember> list = new Contracts.GenericListResult<Contracts.SmallGroupMember>();
Contracts.SmallGroupMemberMapper mapper = new Contracts.SmallGroupMemberMapper();
Contracts.SmallGroupMember member;
CategoryCollection cc = new CategoryCollection();
GroupCollection gc = new GroupCollection();
GroupMember gm;
//
// If they are requesting membership for a person, get the list
// of groups this person is a member of. Does not return groups
// this person is a leader of.
//
list.Items = new List<Contracts.SmallGroupMember>();
list.Start = start;
list.Max = max;
foreach (Category c in cc)
{
gc = new GroupCollection();
gc.LoadByPersonID(id, c.CategoryID);
foreach (Group g in gc)
{
if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, g.GroupClusterID, OperationType.View) == false)
continue;
if (list.Total >= start && list.Items.Count < max)
{
gm = new GroupMember(g.GroupID, id);
member = mapper.FromArena(new GroupMember(g.GroupID, id));
if (member.Group.ID == -1)
continue;
list.Items.Add(mapper.FromArena(gm));
}
list.Total += 1;
}
}
return list;
}
/// <summary>
/// Retrieve a list of all small groups that this person is a leader of.
/// Security is taken into consideration, so if the logged in user does not
/// have permission to see the group, it will not be returned.
/// </summary>
/// <param name="id">The ID number of the person to retrieve membership of.</param>
/// <param name="start">The start index to begin retrieving records at.</param>
/// <param name="max">The maximum number of records to retrieve.</param>
/// <returns>GenericListResult of GenericReference objects.</returns>
[WebGet(UriTemplate = "person/{id}/groupleadership/list?start={start}&max={max}")]
public Contracts.GenericListResult<Contracts.GenericReference> GetPersonSmallGroupLeadership(int id, int start, int max)
{
Contracts.GenericListResult<Contracts.GenericReference> list = new Contracts.GenericListResult<Contracts.GenericReference>();
GroupCollection gc = new GroupCollection();
//
// If they are requesting membership for a person, get the list
// of groups this person is a member of. Does not return groups
// this person is a leader of.
//
list.Items = new List<Contracts.GenericReference>();
gc.LoadByLeaderPersonID(id);
list.Start = start;
list.Max = max;
foreach (Group g in gc)
{
if (RestApi.GroupClusterOperationAllowed(ArenaContext.Current.Person.PersonID, g.GroupClusterID, OperationType.View) == false)
continue;
if (list.Total >= start && list.Items.Count < max)
list.Items.Add(new Contracts.GenericReference(g));
}
return list;
}
/// <summary>
/// Retrieve a list of all profiles that this person is a member of.
/// Security is taken into consideration, so if the logged in user does not
/// have permission to see the tag, it will not be returned.
/// </summary>
/// <param name="id">The ID number of the person to retrieve membership of.</param>
/// <param name="inactive">Wether or not to include inactive membership information.</param>
/// <param name="type">The profile type (personal, ministry, serving) to retrieve membership of.</param>
/// <param name="start">The start index to begin retrieving records at.</param>
/// <param name="max">The maximum number of records to retrieve.</param>
/// <returns>GenericListResult of ProfileMember objects.</returns>
[WebGet(UriTemplate = "person/{id}/profilemembership/list?type={type}&inactive={inactive}&start={start}&max={max}")]
public Contracts.GenericListResult<Contracts.ProfileMember> GetPersonProfileMembership(int id, int type, string inactive, int start, int max)
{
Contracts.GenericListResult<Contracts.ProfileMember> list = new Contracts.GenericListResult<Contracts.ProfileMember>();
ProfileCollection pmc = new ProfileCollection();
bool activeOnly = true;
int i;
//
// Check if they want to include inactive records.
//
try
{
if (Convert.ToInt32(inactive) == 1)
activeOnly = false;
}
catch { }
//
// Check general.
//
if (type == (int)Enums.ProfileType.Ministry && RestApi.PersonFieldOperationAllowed(ArenaContext.Current.Person.PersonID, PersonFields.Activity_Ministry_Tags, OperationType.View) == false)
throw new Exception("Access denied");
else if (type == (int)Enums.ProfileType.Serving && RestApi.PersonFieldOperationAllowed(ArenaContext.Current.Person.PersonID, PersonFields.Activity_Serving_Tags, OperationType.View) == false)
throw new Exception("Access denied");
else if (type != (int)Enums.ProfileType.Personal && type != (int)Enums.ProfileType.Ministry && type != (int)Enums.ProfileType.Serving)
throw new Exception("Access denied");
//
// If they are requesting membership in their own personal profiles
// then retrieve those, otherwise retrieve the general profile
// information.
//
if (type == (int)Enums.ProfileType.Personal)
pmc.LoadMemberPrivateProfiles(RestApi.DefaultOrganizationID(), ArenaContext.Current.Person.PersonID, id, activeOnly);
else
pmc.LoadMemberProfiles(RestApi.DefaultOrganizationID(), (Enums.ProfileType)type, id, activeOnly);
list.Items = new List<Contracts.ProfileMember>();
list.Start = start;
list.Max = max;
foreach (Profile p in pmc)
{
if (RestApi.ProfileOperationAllowed(ArenaContext.Current.Person.PersonID, p.ProfileID, OperationType.View) == false)
continue;
if (list.Total >= start && list.Items.Count < max)
list.Items.Add(new Contracts.ProfileMember(new ProfileMember(p.ProfileID, id)));
list.Total += 1;
}
return list;
}
}
}