1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.ServiceModel;
|
---|
26 | using System.ServiceModel.Channels;
|
---|
27 | using System.Web.Security;
|
---|
28 | using HeuristicLab.GeoIP;
|
---|
29 | using DA = HeuristicLab.Services.Access.DataAccess;
|
---|
30 | using DT = HeuristicLab.Services.Access.DataTransfer;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Services.Access {
|
---|
33 | [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
|
---|
34 | public class AccessService : IAccessService {
|
---|
35 | private IUserManager userManager;
|
---|
36 | private IUserManager UserManager {
|
---|
37 | get {
|
---|
38 | if (userManager == null) userManager = AccessServiceLocator.Instance.UserManager;
|
---|
39 | return userManager;
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | private IRoleVerifier roleVerifier;
|
---|
44 | private IRoleVerifier RoleVerifier {
|
---|
45 | get {
|
---|
46 | if (roleVerifier == null) roleVerifier = AccessServiceLocator.Instance.RoleVerifier;
|
---|
47 | return roleVerifier;
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | #region Client Members
|
---|
52 | public bool ClientExists(Guid id) {
|
---|
53 | if (id != Guid.Empty) {
|
---|
54 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
55 | return (context.Resources.Where(x => x.Id == id).Count() != 0);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public DT.Client GetClient(Guid id) {
|
---|
62 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
63 | var query = from c in context.GetTable<DA.Resource>().OfType<DA.Client>()
|
---|
64 | where c.Id == id
|
---|
65 | select c;
|
---|
66 | if (query.Count() > 0) {
|
---|
67 | return Convert.ToDto(query.FirstOrDefault());
|
---|
68 | } else {
|
---|
69 | return null;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | public IEnumerable<DT.Client> GetClients(IEnumerable<Guid> ids) {
|
---|
75 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
76 | var query = from c in context.GetTable<DA.Resource>().OfType<DA.Client>()
|
---|
77 | where ids.Contains(c.Id)
|
---|
78 | select Convert.ToDto(c);
|
---|
79 | return query.ToList();
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public IEnumerable<DT.Client> GetAllClients() {
|
---|
84 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
85 | var query = from c in context.GetTable<DA.Resource>().OfType<DA.Client>()
|
---|
86 | select Convert.ToDto(c);
|
---|
87 | return query.ToList();
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | public void AddClient(DT.Client client) {
|
---|
92 | string country = string.Empty;
|
---|
93 |
|
---|
94 | OperationContext opContext = OperationContext.Current;
|
---|
95 |
|
---|
96 | if (opContext != null) {
|
---|
97 | MessageProperties properties = opContext.IncomingMessageProperties;
|
---|
98 | RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
|
---|
99 | string ipAdr = endpoint.Address;
|
---|
100 | country = GeoIPLookupService.Instance.GetCountryName(ipAdr);
|
---|
101 | }
|
---|
102 |
|
---|
103 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
104 | DA.Client entity = Convert.ToEntity(client);
|
---|
105 |
|
---|
106 | if (country != string.Empty) {
|
---|
107 | var query = from c in context.GetTable<DA.Country>()
|
---|
108 | where c.Name == country
|
---|
109 | select c;
|
---|
110 | if (query.Count() > 0) {
|
---|
111 | entity.CountryId = query.First().Id;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (entity.OperatingSystem != null) {
|
---|
116 | string osversion = entity.OperatingSystem.Name;
|
---|
117 | var query = from os in context.GetTable<DA.OperatingSystem>()
|
---|
118 | where os.Name == osversion
|
---|
119 | select os;
|
---|
120 | if (query.Count() > 0) {
|
---|
121 | entity.OperatingSystem = query.First();
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | if (entity.ClientType != null) {
|
---|
126 | string cType = entity.ClientType.Name;
|
---|
127 | var query = from t in context.GetTable<DA.ClientType>()
|
---|
128 | where t.Name == cType
|
---|
129 | select t;
|
---|
130 | if (query.Count() > 0) {
|
---|
131 | entity.ClientType = query.First();
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | context.Resources.InsertOnSubmit(entity);
|
---|
136 | context.SubmitChanges();
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | public void UpdateClient(DT.Client client) {
|
---|
141 | string country = string.Empty;
|
---|
142 |
|
---|
143 | OperationContext opContext = OperationContext.Current;
|
---|
144 |
|
---|
145 | if (opContext != null) {
|
---|
146 | MessageProperties properties = opContext.IncomingMessageProperties;
|
---|
147 | RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
|
---|
148 | string ipAdr = endpoint.Address;
|
---|
149 | country = GeoIPLookupService.Instance.GetCountryName(ipAdr);
|
---|
150 | }
|
---|
151 |
|
---|
152 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
153 | var query = from c in context.Resources.OfType<DA.Client>()
|
---|
154 | where c.Id == client.Id
|
---|
155 | select c;
|
---|
156 |
|
---|
157 | if (query.Count() > 0) {
|
---|
158 | var entity = query.First();
|
---|
159 |
|
---|
160 | if (country != string.Empty) {
|
---|
161 | var countryQuery = from c in context.GetTable<DA.Country>()
|
---|
162 | where c.Name == country
|
---|
163 | select c;
|
---|
164 | if (countryQuery.Count() > 0) {
|
---|
165 | entity.CountryId = countryQuery.First().Id;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | entity.Name = client.Name;
|
---|
170 | entity.Description = client.Description;
|
---|
171 | entity.HeuristicLabVersion = client.HeuristicLabVersion;
|
---|
172 | entity.Timestamp = DateTime.Now;
|
---|
173 |
|
---|
174 | context.SubmitChanges();
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | public void DeleteClient(DT.Client client) {
|
---|
180 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
181 |
|
---|
182 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
183 | //load client because we could get a detached object
|
---|
184 | var query = from c in context.GetTable<DA.Resource>().OfType<DA.Client>()
|
---|
185 | where c.Id == client.Id
|
---|
186 | select c;
|
---|
187 | if (query.Count() > 0) {
|
---|
188 |
|
---|
189 | //delete affiliation first
|
---|
190 | var queryMapping = context.ResourceResourceGroups.Where(x => x.ResourceId == client.Id);
|
---|
191 | if (queryMapping.Count() > 0) {
|
---|
192 | context.ResourceResourceGroups.DeleteAllOnSubmit(queryMapping);
|
---|
193 | }
|
---|
194 |
|
---|
195 | context.Resources.DeleteOnSubmit(query.First());
|
---|
196 | context.SubmitChanges();
|
---|
197 | }
|
---|
198 | }
|
---|
199 | }
|
---|
200 | #endregion
|
---|
201 |
|
---|
202 | #region ClientGroup
|
---|
203 | public IEnumerable<DT.ClientGroup> GetAllClientGroups() {
|
---|
204 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
205 | var query = from c in context.GetTable<DA.Resource>().OfType<DA.ClientGroup>()
|
---|
206 | select Convert.ToDto(c);
|
---|
207 | return query.ToList();
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | public IEnumerable<DT.ClientGroup> GetClientGroups(IEnumerable<Guid> ids) {
|
---|
212 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
213 | var query = from c in context.GetTable<DA.Resource>().OfType<DA.ClientGroup>()
|
---|
214 | where ids.Contains(c.Id)
|
---|
215 | select Convert.ToDto(c);
|
---|
216 | return query.ToList();
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | public Guid AddClientGroup(DT.ClientGroup group) {
|
---|
221 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
222 | if (group.Id == Guid.Empty)
|
---|
223 | group.Id = Guid.NewGuid();
|
---|
224 |
|
---|
225 | var entity = Convert.ToEntity(group);
|
---|
226 | context.Resources.InsertOnSubmit(entity);
|
---|
227 | context.SubmitChanges();
|
---|
228 | return entity.Id;
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | public void UpdateClientGroup(DT.ClientGroup clientGroup) {
|
---|
233 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
234 | var query = from g in context.Resources.OfType<DA.ClientGroup>()
|
---|
235 | where g.Id == clientGroup.Id
|
---|
236 | select g;
|
---|
237 |
|
---|
238 | if (query.Count() > 0) {
|
---|
239 | var entity = query.First();
|
---|
240 | entity.Name = clientGroup.Name;
|
---|
241 | entity.Description = clientGroup.Description;
|
---|
242 | context.SubmitChanges();
|
---|
243 | }
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | public void DeleteClientGroup(DT.ClientGroup clientGroup) {
|
---|
248 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
249 |
|
---|
250 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
251 | //load clientGroup because we could get a detached object
|
---|
252 | var query = from c in context.GetTable<DA.Resource>().OfType<DA.ClientGroup>()
|
---|
253 | where c.Id == clientGroup.Id
|
---|
254 | select c;
|
---|
255 | if (query.Count() > 0) {
|
---|
256 | context.Resources.DeleteOnSubmit(query.First());
|
---|
257 | context.SubmitChanges();
|
---|
258 | }
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | public void AddResourceToGroup(DT.Resource resource, DT.ClientGroup group) {
|
---|
263 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
264 | DA.ResourceResourceGroup rrg = new DA.ResourceResourceGroup() {
|
---|
265 | ResourceId = resource.Id,
|
---|
266 | ResourceGroupId = group.Id
|
---|
267 | };
|
---|
268 |
|
---|
269 | context.ResourceResourceGroups.InsertOnSubmit(rrg);
|
---|
270 | context.SubmitChanges();
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | public void RemoveResourceFromGroup(DT.Resource resource, DT.ClientGroup group) {
|
---|
275 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
276 | var query = context.ResourceResourceGroups.Where(x => x.ResourceId == resource.Id && x.ResourceGroupId == group.Id);
|
---|
277 | if (query.Count() > 0) {
|
---|
278 | context.ResourceResourceGroups.DeleteOnSubmit(query.First());
|
---|
279 | context.SubmitChanges();
|
---|
280 | }
|
---|
281 | }
|
---|
282 | }
|
---|
283 | #endregion
|
---|
284 |
|
---|
285 | #region ClientGroupMapping
|
---|
286 | public IEnumerable<DT.ClientGroupMapping> GetClientGroupMapping() {
|
---|
287 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
288 | var query = from c in context.GetTable<DA.ResourceResourceGroup>()
|
---|
289 | select Convert.ToDto(c);
|
---|
290 | return query.ToList();
|
---|
291 | }
|
---|
292 | }
|
---|
293 | #endregion
|
---|
294 |
|
---|
295 | #region Resource
|
---|
296 | public IEnumerable<DT.Resource> GetResources() {
|
---|
297 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
298 | var query = from r in context.Resources
|
---|
299 | select Convert.ToDto(r);
|
---|
300 | return query.ToList();
|
---|
301 | }
|
---|
302 | }
|
---|
303 | #endregion
|
---|
304 |
|
---|
305 | #region ClientLog
|
---|
306 | public DT.ClientLog GetLastClientLog(Guid clientId) {
|
---|
307 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
308 | var query = from r in context.ClientLogs
|
---|
309 | where r.ResourceId == clientId
|
---|
310 | select r;
|
---|
311 | return Convert.ToDto(query.OrderBy(x => x.Timestamp).LastOrDefault());
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | public IEnumerable<DT.ClientLog> GetClientLogs(Guid clientId) {
|
---|
316 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
317 | var query = from r in context.ClientLogs
|
---|
318 | where r.ResourceId == clientId
|
---|
319 | select Convert.ToDto(r);
|
---|
320 | return query.ToList();
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | public IEnumerable<DT.ClientLog> GetClientLogsSince(DateTime startDate) {
|
---|
325 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
326 | var query = from r in context.ClientLogs
|
---|
327 | where r.Timestamp >= startDate
|
---|
328 | select Convert.ToDto(r);
|
---|
329 | return query.ToList();
|
---|
330 | }
|
---|
331 | }
|
---|
332 |
|
---|
333 | public void AddClientLog(DT.ClientLog log) {
|
---|
334 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
335 | context.ClientLogs.InsertOnSubmit(Convert.ToEntity(log));
|
---|
336 | context.SubmitChanges();
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|
340 | public void DeleteClientLog(DT.ClientLog log) {
|
---|
341 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
342 |
|
---|
343 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
344 | context.ClientLogs.DeleteOnSubmit(Convert.ToEntity(log));
|
---|
345 | context.SubmitChanges();
|
---|
346 | }
|
---|
347 | }
|
---|
348 | #endregion
|
---|
349 |
|
---|
350 | #region User
|
---|
351 | private DT.User BuildUserDto(Guid userId) {
|
---|
352 | DA.aspnet_User aspUser = null;
|
---|
353 | DA.aspnet_Membership aspMembership = null;
|
---|
354 | DA.User accessUser = null;
|
---|
355 |
|
---|
356 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
357 | var userQuery = from u in context.aspnet_Users
|
---|
358 | where u.UserId == userId
|
---|
359 | select u;
|
---|
360 | if (userQuery.Count() == 1) {
|
---|
361 | aspUser = userQuery.First();
|
---|
362 | }
|
---|
363 |
|
---|
364 | var memQuery = from u in context.aspnet_Memberships
|
---|
365 | where u.UserId == userId
|
---|
366 | select u;
|
---|
367 | if (memQuery.Count() == 1) {
|
---|
368 | aspMembership = memQuery.First();
|
---|
369 | }
|
---|
370 | }
|
---|
371 |
|
---|
372 | if (aspUser != null || aspMembership != null) {
|
---|
373 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
374 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
375 | where u.Id == userId
|
---|
376 | select u;
|
---|
377 | if (query.Count() == 1) {
|
---|
378 | accessUser = query.First();
|
---|
379 | } else {
|
---|
380 | //if the user is not in the access db add it (this makes it easy to upgrade with an existing asp.net authentication db)
|
---|
381 | DA.User user = new DA.User();
|
---|
382 | user.Id = userId;
|
---|
383 | user.FullName = "Not set";
|
---|
384 | context.UserGroupBases.InsertOnSubmit(user);
|
---|
385 | context.SubmitChanges();
|
---|
386 | accessUser = user;
|
---|
387 | }
|
---|
388 | }
|
---|
389 | }
|
---|
390 |
|
---|
391 | if (aspUser == null || aspMembership == null || accessUser == null) {
|
---|
392 | throw new Exception("User with id " + userId + " not found.");
|
---|
393 | } else {
|
---|
394 | return Convert.ToDto(accessUser, aspUser, aspMembership);
|
---|
395 | }
|
---|
396 | }
|
---|
397 |
|
---|
398 | private DT.LightweightUser BuildLightweightUserDto(Guid userId) {
|
---|
399 | DA.aspnet_User aspUser = null;
|
---|
400 | DA.aspnet_Membership aspMembership = null;
|
---|
401 | DA.User accessUser = null;
|
---|
402 | List<DA.aspnet_Role> roles = new List<DA.aspnet_Role>();
|
---|
403 | List<DA.UserGroup> groups = new List<DA.UserGroup>();
|
---|
404 |
|
---|
405 |
|
---|
406 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
407 | var userQuery = from u in context.aspnet_Users
|
---|
408 | where u.UserId == userId
|
---|
409 | select u;
|
---|
410 |
|
---|
411 | var memQuery = from u in context.aspnet_Memberships
|
---|
412 | where u.UserId == userId
|
---|
413 | select u;
|
---|
414 | if (memQuery.Count() == 1) {
|
---|
415 | aspMembership = memQuery.First();
|
---|
416 | }
|
---|
417 |
|
---|
418 | if (userQuery.Count() == 1) {
|
---|
419 | aspUser = userQuery.First();
|
---|
420 | roles = (from ur in context.aspnet_UsersInRoles
|
---|
421 | where ur.UserId == aspUser.UserId
|
---|
422 | join r in context.aspnet_Roles on ur.RoleId equals r.RoleId
|
---|
423 | select r).ToList();
|
---|
424 | }
|
---|
425 | }
|
---|
426 |
|
---|
427 | if (aspUser != null || aspMembership != null) {
|
---|
428 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
429 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
430 | where u.Id == userId
|
---|
431 | select u;
|
---|
432 | if (query.Count() == 1) {
|
---|
433 | accessUser = query.First();
|
---|
434 | groups = (from ug in context.UserGroupUserGroups
|
---|
435 | where ug.UserGroupId == accessUser.Id
|
---|
436 | join g in context.UserGroupBases.OfType<DA.UserGroup>() on ug.UserGroupUserGroupId equals g.Id
|
---|
437 | select g).ToList();
|
---|
438 | } else {
|
---|
439 | //if the user is not in the access db add it (this makes it easy to upgrade with an existing asp.net authentication db)
|
---|
440 | DA.User user = new DA.User();
|
---|
441 | user.Id = userId;
|
---|
442 | user.FullName = "Not set";
|
---|
443 | context.UserGroupBases.InsertOnSubmit(user);
|
---|
444 | context.SubmitChanges();
|
---|
445 | accessUser = user;
|
---|
446 | }
|
---|
447 | }
|
---|
448 | }
|
---|
449 |
|
---|
450 | if (aspUser == null || accessUser == null || aspMembership == null) {
|
---|
451 | throw new Exception("User with id " + userId + " not found.");
|
---|
452 | } else {
|
---|
453 | return Convert.ToDto(accessUser, aspUser, aspMembership, roles, groups);
|
---|
454 | }
|
---|
455 | }
|
---|
456 |
|
---|
457 | public DT.LightweightUser Login() {
|
---|
458 | Guid userId = UserManager.CurrentUserId;
|
---|
459 | return BuildLightweightUserDto(userId);
|
---|
460 | }
|
---|
461 |
|
---|
462 | public void UpdateLightweightUser(DT.LightweightUser user) {
|
---|
463 | DT.User u = BuildUserDto(user.Id);
|
---|
464 |
|
---|
465 | u.Email = user.EMail;
|
---|
466 | u.FullName = user.FullName;
|
---|
467 |
|
---|
468 | UpdateUser(u);
|
---|
469 | }
|
---|
470 |
|
---|
471 | public IEnumerable<DT.UserGroup> GetGroupsOfCurrentUser() {
|
---|
472 | Guid userId = UserManager.CurrentUserId;
|
---|
473 |
|
---|
474 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
475 | //TODO: this has to be done recursive, so check if a group is in another
|
---|
476 | //group because then the user is also in this group...
|
---|
477 | var query = from g in context.UserGroupUserGroups
|
---|
478 | from ug in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
479 | where g.UserGroupId == userId && g.UserGroupUserGroupId == ug.Id
|
---|
480 | select Convert.ToDto(ug);
|
---|
481 | return query.ToList();
|
---|
482 | }
|
---|
483 | }
|
---|
484 |
|
---|
485 | public IEnumerable<DT.Role> GetRolesOfCurrentUser() {
|
---|
486 | Guid userId = UserManager.CurrentUserId;
|
---|
487 |
|
---|
488 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
489 | var query = from ur in context.aspnet_UsersInRoles
|
---|
490 | from r in context.aspnet_Roles
|
---|
491 | where ur.UserId == userId && ur.RoleId == r.RoleId
|
---|
492 | select Convert.ToDto(r);
|
---|
493 | return query.ToList();
|
---|
494 | }
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | public IEnumerable<DT.LightweightUser> GetAllLightweightUsers() {
|
---|
499 | List<Guid> accessUserGuids = null;
|
---|
500 |
|
---|
501 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
502 | var query = from u in context.aspnet_Users
|
---|
503 | select u.UserId;
|
---|
504 | accessUserGuids = query.ToList();
|
---|
505 | }
|
---|
506 | return accessUserGuids.Select(x => BuildLightweightUserDto(x));
|
---|
507 | }
|
---|
508 |
|
---|
509 | public IEnumerable<DT.User> GetAllUsers() {
|
---|
510 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
511 |
|
---|
512 | List<Guid> accessUserGuids = null;
|
---|
513 |
|
---|
514 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
515 | var query = from u in context.aspnet_Users
|
---|
516 | select u.UserId;
|
---|
517 | accessUserGuids = query.ToList();
|
---|
518 | }
|
---|
519 |
|
---|
520 | return accessUserGuids.Select(x => BuildUserDto(x));
|
---|
521 | }
|
---|
522 |
|
---|
523 | public IEnumerable<DT.User> GetUsers(IEnumerable<Guid> ids) {
|
---|
524 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
525 |
|
---|
526 | List<Guid> accessUserGuids = null;
|
---|
527 |
|
---|
528 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
529 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
530 | where ids.Contains(u.Id)
|
---|
531 | select u.Id;
|
---|
532 | accessUserGuids = query.ToList();
|
---|
533 | }
|
---|
534 |
|
---|
535 | if (accessUserGuids.Count() != ids.Count()) {
|
---|
536 | throw new Exception("Couldn't find one or more users for the given user ids.");
|
---|
537 | }
|
---|
538 |
|
---|
539 | return accessUserGuids.Select(x => BuildUserDto(x));
|
---|
540 | }
|
---|
541 |
|
---|
542 | public IEnumerable<DT.LightweightUser> GetLightweightUsers(IEnumerable<Guid> ids) {
|
---|
543 | List<Guid> accessUserGuids = null;
|
---|
544 |
|
---|
545 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
546 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
547 | where ids.Contains(u.Id)
|
---|
548 | select u.Id;
|
---|
549 | accessUserGuids = query.ToList();
|
---|
550 | }
|
---|
551 |
|
---|
552 | if (accessUserGuids.Count() != ids.Count()) {
|
---|
553 | throw new Exception("Couldn't find one or more users for the given user ids.");
|
---|
554 | }
|
---|
555 |
|
---|
556 | return accessUserGuids.Select(x => BuildLightweightUserDto(x));
|
---|
557 | }
|
---|
558 |
|
---|
559 | public DT.User AddUser(DT.User user) {
|
---|
560 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
561 |
|
---|
562 | DA.User accessUser;
|
---|
563 | DA.aspnet_User aspUser;
|
---|
564 | DA.aspnet_Membership aspMembership;
|
---|
565 | bool userExistsInASP;
|
---|
566 |
|
---|
567 | Convert.ToEntity(user, out accessUser, out aspUser, out aspMembership, out userExistsInASP);
|
---|
568 |
|
---|
569 | if (userExistsInASP) {
|
---|
570 | if (accessUser.Id == null || accessUser.Id == Guid.Empty) {
|
---|
571 | accessUser.Id = aspMembership.UserId;
|
---|
572 | }
|
---|
573 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
574 | context.UserGroupBases.InsertOnSubmit(accessUser);
|
---|
575 | context.SubmitChanges();
|
---|
576 | }
|
---|
577 | MembershipUser membershipUser = Membership.GetUser((object)accessUser.Id);
|
---|
578 | if (membershipUser != null) {
|
---|
579 | membershipUser.Email = aspMembership.Email;
|
---|
580 | membershipUser.IsApproved = aspMembership.IsApproved;
|
---|
581 | membershipUser.Comment = aspMembership.Comment;
|
---|
582 | Membership.UpdateUser(membershipUser);
|
---|
583 | }
|
---|
584 | } else {
|
---|
585 | MembershipUser membershipUser = Membership.CreateUser(aspUser.UserName, aspUser.UserName, aspMembership.Email);
|
---|
586 | membershipUser.IsApproved = aspMembership.IsApproved;
|
---|
587 | membershipUser.Comment = aspMembership.Comment;
|
---|
588 | Membership.UpdateUser(membershipUser);
|
---|
589 |
|
---|
590 | Guid userId = (Guid)membershipUser.ProviderUserKey;
|
---|
591 | accessUser.Id = userId;
|
---|
592 |
|
---|
593 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
594 | context.UserGroupBases.InsertOnSubmit(accessUser);
|
---|
595 | context.SubmitChanges();
|
---|
596 | }
|
---|
597 | }
|
---|
598 |
|
---|
599 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
600 | var newAspUser = context.aspnet_Users.Where(x => x.UserId == accessUser.Id).FirstOrDefault();
|
---|
601 | var newAspMembership = context.aspnet_Memberships.Where(x => x.UserId == accessUser.Id).FirstOrDefault();
|
---|
602 | return Convert.ToDto(accessUser, newAspUser, newAspMembership);
|
---|
603 | }
|
---|
604 | }
|
---|
605 |
|
---|
606 | public void DeleteUser(DT.User user) {
|
---|
607 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
608 |
|
---|
609 | if (user.Id != null && user.Id != Guid.Empty) {
|
---|
610 | //delete asp.net user
|
---|
611 | Membership.DeleteUser(user.UserName);
|
---|
612 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
613 | var query = context.UserGroupBases.OfType<DA.User>().Where(x => x.Id == user.Id);
|
---|
614 | if (query.Count() > 0) {
|
---|
615 |
|
---|
616 | //delete affiliation first
|
---|
617 | var queryMapping = context.UserGroupUserGroups.Where(x => x.UserGroupId == user.Id);
|
---|
618 | if (queryMapping.Count() > 0) {
|
---|
619 | context.UserGroupUserGroups.DeleteAllOnSubmit(queryMapping);
|
---|
620 | }
|
---|
621 |
|
---|
622 | //delete user from access db
|
---|
623 | context.UserGroupBases.DeleteOnSubmit(query.First());
|
---|
624 | context.SubmitChanges();
|
---|
625 | }
|
---|
626 | }
|
---|
627 | }
|
---|
628 | }
|
---|
629 |
|
---|
630 | public void UpdateUser(DT.User user) {
|
---|
631 | if (user.Id != UserManager.CurrentUserId) {
|
---|
632 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
633 | }
|
---|
634 |
|
---|
635 | MembershipUser membershipUser = Membership.GetUser((object)user.Id);
|
---|
636 | if (membershipUser != null) {
|
---|
637 | membershipUser.Email = user.Email;
|
---|
638 | membershipUser.IsApproved = user.IsApproved;
|
---|
639 | membershipUser.Comment = user.Comment;
|
---|
640 | Membership.UpdateUser(membershipUser);
|
---|
641 | }
|
---|
642 |
|
---|
643 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
644 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
645 | where u.Id == user.Id
|
---|
646 | select u;
|
---|
647 | if (query.Count() > 0) {
|
---|
648 | DA.User u = query.First();
|
---|
649 | u.FullName = user.FullName;
|
---|
650 | context.SubmitChanges();
|
---|
651 | }
|
---|
652 | }
|
---|
653 | }
|
---|
654 |
|
---|
655 | public void AddUserToRole(DT.Role role, DT.User user) {
|
---|
656 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
657 |
|
---|
658 | //TODO: usernames and rolenames have to be unique!
|
---|
659 | MembershipUser msUser = Membership.GetUser((object)user.Id);
|
---|
660 | if (msUser != null) {
|
---|
661 | Roles.AddUserToRole(msUser.UserName, role.Name);
|
---|
662 | }
|
---|
663 | }
|
---|
664 |
|
---|
665 | public void RemoveUserFromRole(DT.Role role, DT.User user) {
|
---|
666 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
667 |
|
---|
668 | MembershipUser msUser = Membership.GetUser((object)user.Id);
|
---|
669 | if (msUser != null) {
|
---|
670 | Roles.RemoveUserFromRole(msUser.UserName, role.Name);
|
---|
671 | }
|
---|
672 | }
|
---|
673 |
|
---|
674 | public bool ChangePassword(Guid userId, string oldPassword, string newPassword) {
|
---|
675 | MembershipUser msUser = Membership.GetUser(userId);
|
---|
676 | if (msUser != null) {
|
---|
677 | return msUser.ChangePassword(oldPassword, newPassword);
|
---|
678 | }
|
---|
679 | return false;
|
---|
680 | }
|
---|
681 |
|
---|
682 | public string ResetPassword(Guid userId) {
|
---|
683 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
684 |
|
---|
685 | MembershipUser msUser = Membership.GetUser(userId);
|
---|
686 | if (msUser != null) {
|
---|
687 | return msUser.ResetPassword();
|
---|
688 | } else {
|
---|
689 | throw new Exception("Password reset failed.");
|
---|
690 | }
|
---|
691 | }
|
---|
692 | #endregion
|
---|
693 |
|
---|
694 | #region UserGroup
|
---|
695 | public IEnumerable<DT.UserGroup> GetAllUserGroups() {
|
---|
696 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
697 | var query = from u in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
698 | select Convert.ToDto(u);
|
---|
699 | return query.ToList();
|
---|
700 | }
|
---|
701 | }
|
---|
702 |
|
---|
703 | public IEnumerable<DT.UserGroup> GetUserGroupsOfUser(Guid userId) {
|
---|
704 |
|
---|
705 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
706 | var groupIds = from g in context.UserGroupUserGroups
|
---|
707 | where g.UserGroupId == userId
|
---|
708 | select g.UserGroupUserGroupId;
|
---|
709 |
|
---|
710 | var query = from g in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
711 | where groupIds.Contains(g.Id)
|
---|
712 | select Convert.ToDto(g);
|
---|
713 |
|
---|
714 | return query.ToList();
|
---|
715 | }
|
---|
716 | }
|
---|
717 |
|
---|
718 | public IEnumerable<DT.UserGroup> GetUserGroups(IEnumerable<Guid> ids) {
|
---|
719 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
720 | var query = from u in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
721 | where ids.Contains(u.Id)
|
---|
722 | select Convert.ToDto(u);
|
---|
723 | return query.ToList();
|
---|
724 | }
|
---|
725 | }
|
---|
726 |
|
---|
727 | public Guid AddUserGroup(DT.UserGroup group) {
|
---|
728 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
729 | //because id is not automatically set because of user, we have to do it here manually for group
|
---|
730 | group.Id = Guid.NewGuid();
|
---|
731 |
|
---|
732 | context.UserGroupBases.InsertOnSubmit(Convert.ToEntity(group));
|
---|
733 | context.SubmitChanges();
|
---|
734 | return group.Id;
|
---|
735 | }
|
---|
736 | }
|
---|
737 |
|
---|
738 | public void UpdateUserGroup(DT.UserGroup group) {
|
---|
739 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
740 | DA.UserGroup entity = context.UserGroupBases.OfType<DA.UserGroup>().FirstOrDefault(x => x.Id == group.Id);
|
---|
741 | Convert.ToEntity(group, entity);
|
---|
742 | context.SubmitChanges();
|
---|
743 | }
|
---|
744 | }
|
---|
745 |
|
---|
746 | public void DeleteUserGroup(DT.UserGroup group) {
|
---|
747 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
748 | var g = group; //linq does not like vars called group
|
---|
749 |
|
---|
750 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
751 | var query = from ug in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
752 | where ug.Id == g.Id
|
---|
753 | select ug;
|
---|
754 | if (query.Count() > 0) {
|
---|
755 | context.UserGroupBases.DeleteOnSubmit(query.First());
|
---|
756 | context.SubmitChanges();
|
---|
757 | } else {
|
---|
758 | throw new Exception("UserGroup with id " + g.Id + " does not exist.");
|
---|
759 | }
|
---|
760 | }
|
---|
761 | }
|
---|
762 |
|
---|
763 | public void AddUserGroupBaseToGroup(DT.UserGroupBase resource, DT.UserGroup group) {
|
---|
764 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
765 | DA.UserGroupUserGroup ugug = new DA.UserGroupUserGroup();
|
---|
766 | ugug.UserGroupId = resource.Id;
|
---|
767 | ugug.UserGroupUserGroupId = group.Id;
|
---|
768 | context.UserGroupUserGroups.InsertOnSubmit(ugug);
|
---|
769 | context.SubmitChanges();
|
---|
770 | }
|
---|
771 | }
|
---|
772 |
|
---|
773 | public void RemoveUserGroupBaseFromGroup(DT.UserGroupBase resource, DT.UserGroup userGroup) {
|
---|
774 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
775 | var query = from u in context.UserGroupUserGroups
|
---|
776 | where u.UserGroupId == resource.Id && u.UserGroupUserGroupId == userGroup.Id
|
---|
777 | select u;
|
---|
778 |
|
---|
779 | if (query.Count() == 1) {
|
---|
780 | context.UserGroupUserGroups.DeleteOnSubmit(query.First());
|
---|
781 | context.SubmitChanges();
|
---|
782 | }
|
---|
783 | }
|
---|
784 | }
|
---|
785 |
|
---|
786 | public IEnumerable<DT.UserGroupBase> GetUsersAndGroups() {
|
---|
787 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
788 | var query = from u in context.UserGroupBases
|
---|
789 | select Convert.ToDto(u);
|
---|
790 | return query.ToList();
|
---|
791 | }
|
---|
792 | }
|
---|
793 |
|
---|
794 | public IEnumerable<DT.UserGroupMapping> GetUserGroupMapping() {
|
---|
795 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
796 | var query = from u in context.UserGroupUserGroups
|
---|
797 | select Convert.ToDto(u);
|
---|
798 | return query.ToList();
|
---|
799 | }
|
---|
800 | }
|
---|
801 |
|
---|
802 | public IEnumerable<Guid> GetUserGroupIdsOfGroup(Guid groupId) {
|
---|
803 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
804 | var query = from u in context.UserGroupUserGroups
|
---|
805 | where u.UserGroupUserGroupId == groupId
|
---|
806 | select u.UserGroupId;
|
---|
807 | return query.ToList();
|
---|
808 | }
|
---|
809 | }
|
---|
810 | #endregion
|
---|
811 |
|
---|
812 | #region UserGroupBase
|
---|
813 | public IEnumerable<DT.UserGroupBase> GetAllLeightweightUsersAndGroups() {
|
---|
814 | //TODO: it must be possible to include a role so not all users are returned but only the ones who are allowed to use a certain service
|
---|
815 | List<DT.UserGroup> userGroups = new List<DT.UserGroup>();
|
---|
816 | List<DT.UserGroupBase> result = new List<DT.UserGroupBase>();
|
---|
817 |
|
---|
818 | // this is just for generating users from asp.net authenticaton db; we should maybe provide an updatescript instead
|
---|
819 | List<Guid> accessUserGuids = null;
|
---|
820 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
821 | var query = from u in context.aspnet_Users
|
---|
822 | select u.UserId;
|
---|
823 | accessUserGuids = query.ToList();
|
---|
824 | }
|
---|
825 | var lightweightUsers = accessUserGuids.Select(x => BuildLightweightUserDto(x));
|
---|
826 |
|
---|
827 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
828 | var query = from u in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
829 | select Convert.ToDto(u);
|
---|
830 | userGroups = query.ToList();
|
---|
831 | }
|
---|
832 |
|
---|
833 | result.AddRange(lightweightUsers);
|
---|
834 | result.AddRange(userGroups);
|
---|
835 |
|
---|
836 | return result;
|
---|
837 | }
|
---|
838 |
|
---|
839 | public IEnumerable<DT.UserGroupBase> GetLeightweightUsersAndGroups(IEnumerable<Guid> ids) {
|
---|
840 | List<DA.UserGroupBase> dbUserGroupsBases = new List<DA.UserGroupBase>();
|
---|
841 | List<DT.UserGroupBase> result = new List<DT.UserGroupBase>();
|
---|
842 |
|
---|
843 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
844 | var query = from u in context.UserGroupBases
|
---|
845 | where ids.Contains(u.Id)
|
---|
846 | select u;
|
---|
847 | dbUserGroupsBases = query.ToList();
|
---|
848 | }
|
---|
849 |
|
---|
850 | foreach (var ugb in dbUserGroupsBases) {
|
---|
851 | if (ugb.GetType() == typeof(DA.User)) {
|
---|
852 | var user = BuildLightweightUserDto(ugb.Id);
|
---|
853 | result.Add(user);
|
---|
854 | } else if (ugb.GetType() == typeof(DA.UserGroup)) {
|
---|
855 | var group = Convert.ToDto(ugb as DA.UserGroup);
|
---|
856 | result.Add(group);
|
---|
857 | }
|
---|
858 | }
|
---|
859 | return result;
|
---|
860 | }
|
---|
861 | #endregion
|
---|
862 |
|
---|
863 | #region Roles
|
---|
864 | public IEnumerable<DT.Role> GetRoles() {
|
---|
865 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
866 | var query = from u in context.aspnet_Roles
|
---|
867 | select Convert.ToDto(u);
|
---|
868 | return query.ToList();
|
---|
869 | }
|
---|
870 | }
|
---|
871 |
|
---|
872 | public DT.Role AddRole(DT.Role role) {
|
---|
873 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
874 |
|
---|
875 | Roles.CreateRole(role.Name);
|
---|
876 | return role;
|
---|
877 | }
|
---|
878 |
|
---|
879 | public void DeleteRole(DT.Role role) {
|
---|
880 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
881 |
|
---|
882 | Roles.DeleteRole(role.Name);
|
---|
883 | }
|
---|
884 |
|
---|
885 | public IEnumerable<DT.Role> GetUserRoles(DT.User user) {
|
---|
886 | var roles = Roles.GetRolesForUser(user.UserName);
|
---|
887 | return roles.Select(x => new DT.Role() { Name = x });
|
---|
888 | }
|
---|
889 |
|
---|
890 | public void AddRoleToGroup(DT.UserGroup userGroup, DT.Role role) {
|
---|
891 | Guid[] userIds;
|
---|
892 | string[] aspUsers;
|
---|
893 |
|
---|
894 | using (DA.AccessServiceDataContext accessContext = new DA.AccessServiceDataContext()) {
|
---|
895 | userIds = (from u in accessContext.UserGroupUserGroups
|
---|
896 | where u.UserGroupUserGroupId == userGroup.Id
|
---|
897 | select u.UserGroupId).ToArray();
|
---|
898 | }
|
---|
899 |
|
---|
900 | using (DA.ASPNETAuthenticationDataContext aspContext = new DA.ASPNETAuthenticationDataContext()) {
|
---|
901 | aspUsers = (from u in aspContext.aspnet_Users
|
---|
902 | where userIds.Contains(u.UserId)
|
---|
903 | select u.UserName).ToArray();
|
---|
904 | }
|
---|
905 |
|
---|
906 | Roles.AddUsersToRole(aspUsers, role.Name);
|
---|
907 |
|
---|
908 | }
|
---|
909 |
|
---|
910 | public void RemoveRoleFromGroup(DT.UserGroup userGroup, DT.Role role) {
|
---|
911 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
912 |
|
---|
913 | Guid[] userIds;
|
---|
914 | string[] aspUsers;
|
---|
915 |
|
---|
916 | using (DA.AccessServiceDataContext accessContext = new DA.AccessServiceDataContext()) {
|
---|
917 | userIds = (from u in accessContext.UserGroupUserGroups
|
---|
918 | where u.UserGroupUserGroupId == userGroup.Id
|
---|
919 | select u.UserGroupId).ToArray();
|
---|
920 | }
|
---|
921 |
|
---|
922 | using (DA.ASPNETAuthenticationDataContext aspContext = new DA.ASPNETAuthenticationDataContext()) {
|
---|
923 | aspUsers = (from u in aspContext.aspnet_Users
|
---|
924 | where userIds.Contains(u.UserId)
|
---|
925 | select u.UserName).ToArray();
|
---|
926 | }
|
---|
927 |
|
---|
928 | Roles.RemoveUsersFromRole(aspUsers.ToArray(), role.Name);
|
---|
929 | }
|
---|
930 | #endregion
|
---|
931 |
|
---|
932 | #region Error Reporting
|
---|
933 | public void ReportError(DT.ClientError error) {
|
---|
934 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
935 | context.ClientErrors.InsertOnSubmit(Convert.ToEntity(error));
|
---|
936 | context.SubmitChanges();
|
---|
937 | }
|
---|
938 | }
|
---|
939 |
|
---|
940 | public IEnumerable<DT.ClientError> GetClientErrors() {
|
---|
941 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
942 |
|
---|
943 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
944 | var query = from c in context.ClientErrors
|
---|
945 | select Convert.ToDto(c);
|
---|
946 | return query.ToList();
|
---|
947 | }
|
---|
948 | }
|
---|
949 |
|
---|
950 | public IEnumerable<DT.ClientError> GetLastClientErrors(DateTime startDate) {
|
---|
951 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
952 |
|
---|
953 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
954 | var query = from c in context.ClientErrors
|
---|
955 | where c.Timestamp >= startDate
|
---|
956 | select Convert.ToDto(c);
|
---|
957 | return query.ToList();
|
---|
958 | }
|
---|
959 | }
|
---|
960 |
|
---|
961 | public void DeleteError(DT.ClientError error) {
|
---|
962 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
963 |
|
---|
964 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
965 | var query = context.ClientErrors.Where(x => x.Id == error.Id);
|
---|
966 | if (query.Count() > 0) {
|
---|
967 | context.ClientErrors.DeleteOnSubmit(query.First());
|
---|
968 | context.SubmitChanges();
|
---|
969 | }
|
---|
970 | }
|
---|
971 | }
|
---|
972 | #endregion
|
---|
973 | }
|
---|
974 | }
|
---|