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.User accessUser = null;
|
---|
401 | List<DA.aspnet_Role> roles = new List<DA.aspnet_Role>();
|
---|
402 | List<DA.UserGroup> groups = new List<DA.UserGroup>();
|
---|
403 |
|
---|
404 |
|
---|
405 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
406 | var userQuery = from u in context.aspnet_Users
|
---|
407 | where u.UserId == userId
|
---|
408 | select u;
|
---|
409 | if (userQuery.Count() == 1) {
|
---|
410 | aspUser = userQuery.First();
|
---|
411 | roles = (from ur in context.aspnet_UsersInRoles
|
---|
412 | where ur.UserId == aspUser.UserId
|
---|
413 | join r in context.aspnet_Roles on ur.RoleId equals r.RoleId
|
---|
414 | select r).ToList();
|
---|
415 | }
|
---|
416 | }
|
---|
417 |
|
---|
418 | if (aspUser != null) {
|
---|
419 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
420 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
421 | where u.Id == userId
|
---|
422 | select u;
|
---|
423 | if (query.Count() == 1) {
|
---|
424 | accessUser = query.First();
|
---|
425 | groups = (from ug in context.UserGroupUserGroups
|
---|
426 | where ug.UserGroupId == accessUser.Id
|
---|
427 | join g in context.UserGroupBases.OfType<DA.UserGroup>() on ug.UserGroupUserGroupId equals g.Id
|
---|
428 | select g).ToList();
|
---|
429 | } else {
|
---|
430 | //if the user is not in the access db add it (this makes it easy to upgrade with an existing asp.net authentication db)
|
---|
431 | DA.User user = new DA.User();
|
---|
432 | user.Id = userId;
|
---|
433 | user.FullName = "Not set";
|
---|
434 | context.UserGroupBases.InsertOnSubmit(user);
|
---|
435 | context.SubmitChanges();
|
---|
436 | accessUser = user;
|
---|
437 | }
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | if (aspUser == null || accessUser == null) {
|
---|
442 | throw new Exception("User with id " + userId + " not found.");
|
---|
443 | } else {
|
---|
444 | return Convert.ToDto(accessUser, aspUser, roles, groups);
|
---|
445 | }
|
---|
446 | }
|
---|
447 |
|
---|
448 | public DT.LightweightUser Login() {
|
---|
449 | Guid userId = UserManager.CurrentUserId;
|
---|
450 | return BuildLightweightUserDto(userId);
|
---|
451 | }
|
---|
452 |
|
---|
453 | public IEnumerable<DT.UserGroup> GetGroupsOfCurrentUser() {
|
---|
454 | Guid userId = UserManager.CurrentUserId;
|
---|
455 |
|
---|
456 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
457 | //TODO: this has to be done recursive, so check if a group is in another
|
---|
458 | //group because then the user is also in this group...
|
---|
459 | var query = from g in context.UserGroupUserGroups
|
---|
460 | from ug in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
461 | where g.UserGroupId == userId && g.UserGroupUserGroupId == ug.Id
|
---|
462 | select Convert.ToDto(ug);
|
---|
463 | return query.ToList();
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | public IEnumerable<DT.Role> GetRolesOfCurrentUser() {
|
---|
468 | Guid userId = UserManager.CurrentUserId;
|
---|
469 |
|
---|
470 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
471 | var query = from ur in context.aspnet_UsersInRoles
|
---|
472 | from r in context.aspnet_Roles
|
---|
473 | where ur.UserId == userId && ur.RoleId == r.RoleId
|
---|
474 | select Convert.ToDto(r);
|
---|
475 | return query.ToList();
|
---|
476 | }
|
---|
477 | }
|
---|
478 |
|
---|
479 |
|
---|
480 | public IEnumerable<DT.LightweightUser> GetAllLightweightUsers() {
|
---|
481 | List<Guid> accessUserGuids = null;
|
---|
482 |
|
---|
483 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
484 | var query = from u in context.aspnet_Users
|
---|
485 | select u.UserId;
|
---|
486 | accessUserGuids = query.ToList();
|
---|
487 | }
|
---|
488 | return accessUserGuids.Select(x => BuildLightweightUserDto(x));
|
---|
489 | }
|
---|
490 |
|
---|
491 | public IEnumerable<DT.User> GetAllUsers() {
|
---|
492 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
493 |
|
---|
494 | List<Guid> accessUserGuids = null;
|
---|
495 |
|
---|
496 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
497 | var query = from u in context.aspnet_Users
|
---|
498 | select u.UserId;
|
---|
499 | accessUserGuids = query.ToList();
|
---|
500 | }
|
---|
501 |
|
---|
502 | return accessUserGuids.Select(x => BuildUserDto(x));
|
---|
503 | }
|
---|
504 |
|
---|
505 | public IEnumerable<DT.User> GetUsers(IEnumerable<Guid> ids) {
|
---|
506 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
507 |
|
---|
508 | List<Guid> accessUserGuids = null;
|
---|
509 |
|
---|
510 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
511 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
512 | where ids.Contains(u.Id)
|
---|
513 | select u.Id;
|
---|
514 | accessUserGuids = query.ToList();
|
---|
515 | }
|
---|
516 |
|
---|
517 | if (accessUserGuids.Count() != ids.Count()) {
|
---|
518 | throw new Exception("Couldn't find one or more users for the given user ids.");
|
---|
519 | }
|
---|
520 |
|
---|
521 | return accessUserGuids.Select(x => BuildUserDto(x));
|
---|
522 | }
|
---|
523 |
|
---|
524 | public IEnumerable<DT.LightweightUser> GetLightweightUsers(IEnumerable<Guid> ids) {
|
---|
525 | List<Guid> accessUserGuids = null;
|
---|
526 |
|
---|
527 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
528 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
529 | where ids.Contains(u.Id)
|
---|
530 | select u.Id;
|
---|
531 | accessUserGuids = query.ToList();
|
---|
532 | }
|
---|
533 |
|
---|
534 | if (accessUserGuids.Count() != ids.Count()) {
|
---|
535 | throw new Exception("Couldn't find one or more users for the given user ids.");
|
---|
536 | }
|
---|
537 |
|
---|
538 | return accessUserGuids.Select(x => BuildLightweightUserDto(x));
|
---|
539 | }
|
---|
540 |
|
---|
541 | public DT.User AddUser(DT.User user) {
|
---|
542 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
543 |
|
---|
544 | DA.User accessUser;
|
---|
545 | DA.aspnet_User aspUser;
|
---|
546 | DA.aspnet_Membership aspMembership;
|
---|
547 | bool userExistsInASP;
|
---|
548 |
|
---|
549 | Convert.ToEntity(user, out accessUser, out aspUser, out aspMembership, out userExistsInASP);
|
---|
550 |
|
---|
551 | if (userExistsInASP) {
|
---|
552 | if (accessUser.Id == null || accessUser.Id == Guid.Empty) {
|
---|
553 | accessUser.Id = aspMembership.UserId;
|
---|
554 | }
|
---|
555 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
556 | context.UserGroupBases.InsertOnSubmit(accessUser);
|
---|
557 | context.SubmitChanges();
|
---|
558 | }
|
---|
559 | MembershipUser membershipUser = Membership.GetUser((object)accessUser.Id);
|
---|
560 | if (membershipUser != null) {
|
---|
561 | membershipUser.Email = aspMembership.Email;
|
---|
562 | membershipUser.IsApproved = aspMembership.IsApproved;
|
---|
563 | membershipUser.Comment = aspMembership.Comment;
|
---|
564 | Membership.UpdateUser(membershipUser);
|
---|
565 | }
|
---|
566 | } else {
|
---|
567 | MembershipUser membershipUser = Membership.CreateUser(aspUser.UserName, aspUser.UserName, aspMembership.Email);
|
---|
568 | membershipUser.IsApproved = aspMembership.IsApproved;
|
---|
569 | membershipUser.Comment = aspMembership.Comment;
|
---|
570 | Membership.UpdateUser(membershipUser);
|
---|
571 |
|
---|
572 | Guid userId = (Guid)membershipUser.ProviderUserKey;
|
---|
573 | accessUser.Id = userId;
|
---|
574 |
|
---|
575 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
576 | context.UserGroupBases.InsertOnSubmit(accessUser);
|
---|
577 | context.SubmitChanges();
|
---|
578 | }
|
---|
579 | }
|
---|
580 |
|
---|
581 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
582 | var newAspUser = context.aspnet_Users.Where(x => x.UserId == accessUser.Id).FirstOrDefault();
|
---|
583 | var newAspMembership = context.aspnet_Memberships.Where(x => x.UserId == accessUser.Id).FirstOrDefault();
|
---|
584 | return Convert.ToDto(accessUser, newAspUser, newAspMembership);
|
---|
585 | }
|
---|
586 | }
|
---|
587 |
|
---|
588 | public void DeleteUser(DT.User user) {
|
---|
589 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
590 |
|
---|
591 | if (user.Id != null && user.Id != Guid.Empty) {
|
---|
592 | //delete asp.net user
|
---|
593 | Membership.DeleteUser(user.UserName);
|
---|
594 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
595 | var query = context.UserGroupBases.OfType<DA.User>().Where(x => x.Id == user.Id);
|
---|
596 | if (query.Count() > 0) {
|
---|
597 |
|
---|
598 | //delete affiliation first
|
---|
599 | var queryMapping = context.UserGroupUserGroups.Where(x => x.UserGroupId == user.Id);
|
---|
600 | if (queryMapping.Count() > 0) {
|
---|
601 | context.UserGroupUserGroups.DeleteAllOnSubmit(queryMapping);
|
---|
602 | }
|
---|
603 |
|
---|
604 | //delete user from access db
|
---|
605 | context.UserGroupBases.DeleteOnSubmit(query.First());
|
---|
606 | context.SubmitChanges();
|
---|
607 | }
|
---|
608 | }
|
---|
609 | }
|
---|
610 | }
|
---|
611 |
|
---|
612 | public void UpdateUser(DT.User user) {
|
---|
613 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
614 |
|
---|
615 | MembershipUser membershipUser = Membership.GetUser((object)user.Id);
|
---|
616 | if (membershipUser != null) {
|
---|
617 | membershipUser.Email = user.Email;
|
---|
618 | membershipUser.IsApproved = user.IsApproved;
|
---|
619 | membershipUser.Comment = user.Comment;
|
---|
620 | Membership.UpdateUser(membershipUser);
|
---|
621 | }
|
---|
622 |
|
---|
623 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
624 | var query = from u in context.UserGroupBases.OfType<DA.User>()
|
---|
625 | where u.Id == user.Id
|
---|
626 | select u;
|
---|
627 | if (query.Count() > 0) {
|
---|
628 | DA.User u = query.First();
|
---|
629 | u.FullName = user.FullName;
|
---|
630 | context.SubmitChanges();
|
---|
631 | }
|
---|
632 | }
|
---|
633 | }
|
---|
634 |
|
---|
635 | public void AddUserToRole(DT.Role role, DT.User user) {
|
---|
636 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
637 |
|
---|
638 | //TODO: usernames and rolenames have to be unique!
|
---|
639 | MembershipUser msUser = Membership.GetUser((object)user.Id);
|
---|
640 | if (msUser != null) {
|
---|
641 | Roles.AddUserToRole(msUser.UserName, role.Name);
|
---|
642 | }
|
---|
643 | }
|
---|
644 |
|
---|
645 | public void RemoveUserFromRole(DT.Role role, DT.User user) {
|
---|
646 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
647 |
|
---|
648 | MembershipUser msUser = Membership.GetUser((object)user.Id);
|
---|
649 | if (msUser != null) {
|
---|
650 | Roles.RemoveUserFromRole(msUser.UserName, role.Name);
|
---|
651 | }
|
---|
652 | }
|
---|
653 |
|
---|
654 | public bool ChangePassword(Guid userId, string oldPassword, string newPassword) {
|
---|
655 | MembershipUser msUser = Membership.GetUser(userId);
|
---|
656 | if (msUser != null) {
|
---|
657 | return msUser.ChangePassword(oldPassword, newPassword);
|
---|
658 | }
|
---|
659 | return false;
|
---|
660 | }
|
---|
661 |
|
---|
662 | public string ResetPassword(Guid userId) {
|
---|
663 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
664 |
|
---|
665 | MembershipUser msUser = Membership.GetUser(userId);
|
---|
666 | if (msUser != null) {
|
---|
667 | return msUser.ResetPassword();
|
---|
668 | } else {
|
---|
669 | throw new Exception("Password reset failed.");
|
---|
670 | }
|
---|
671 | }
|
---|
672 | #endregion
|
---|
673 |
|
---|
674 | #region UserGroup
|
---|
675 | public IEnumerable<DT.UserGroup> GetAllUserGroups() {
|
---|
676 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
677 | var query = from u in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
678 | select Convert.ToDto(u);
|
---|
679 | return query.ToList();
|
---|
680 | }
|
---|
681 | }
|
---|
682 |
|
---|
683 | public IEnumerable<DT.UserGroup> GetUserGroupsOfUser(Guid userId) {
|
---|
684 |
|
---|
685 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
686 | var groupIds = from g in context.UserGroupUserGroups
|
---|
687 | where g.UserGroupId == userId
|
---|
688 | select g.UserGroupUserGroupId;
|
---|
689 |
|
---|
690 | var query = from g in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
691 | where groupIds.Contains(g.Id)
|
---|
692 | select Convert.ToDto(g);
|
---|
693 |
|
---|
694 | return query.ToList();
|
---|
695 | }
|
---|
696 | }
|
---|
697 |
|
---|
698 | public IEnumerable<DT.UserGroup> GetUserGroups(IEnumerable<Guid> ids) {
|
---|
699 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
700 | var query = from u in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
701 | where ids.Contains(u.Id)
|
---|
702 | select Convert.ToDto(u);
|
---|
703 | return query.ToList();
|
---|
704 | }
|
---|
705 | }
|
---|
706 |
|
---|
707 | public Guid AddUserGroup(DT.UserGroup group) {
|
---|
708 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
709 | //because id is not automatically set because of user, we have to do it here manually for group
|
---|
710 | group.Id = Guid.NewGuid();
|
---|
711 |
|
---|
712 | context.UserGroupBases.InsertOnSubmit(Convert.ToEntity(group));
|
---|
713 | context.SubmitChanges();
|
---|
714 | return group.Id;
|
---|
715 | }
|
---|
716 | }
|
---|
717 |
|
---|
718 | public void UpdateUserGroup(DT.UserGroup group) {
|
---|
719 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
720 | DA.UserGroup entity = context.UserGroupBases.OfType<DA.UserGroup>().FirstOrDefault(x => x.Id == group.Id);
|
---|
721 | Convert.ToEntity(group, entity);
|
---|
722 | context.SubmitChanges();
|
---|
723 | }
|
---|
724 | }
|
---|
725 |
|
---|
726 | public void DeleteUserGroup(DT.UserGroup group) {
|
---|
727 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
728 | var g = group; //linq does not like vars called group
|
---|
729 |
|
---|
730 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
731 | var query = from ug in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
732 | where ug.Id == g.Id
|
---|
733 | select ug;
|
---|
734 | if (query.Count() > 0) {
|
---|
735 | context.UserGroupBases.DeleteOnSubmit(query.First());
|
---|
736 | context.SubmitChanges();
|
---|
737 | } else {
|
---|
738 | throw new Exception("UserGroup with id " + g.Id + " does not exist.");
|
---|
739 | }
|
---|
740 | }
|
---|
741 | }
|
---|
742 |
|
---|
743 | public void AddUserGroupBaseToGroup(DT.UserGroupBase resource, DT.UserGroup group) {
|
---|
744 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
745 | DA.UserGroupUserGroup ugug = new DA.UserGroupUserGroup();
|
---|
746 | ugug.UserGroupId = resource.Id;
|
---|
747 | ugug.UserGroupUserGroupId = group.Id;
|
---|
748 | context.UserGroupUserGroups.InsertOnSubmit(ugug);
|
---|
749 | context.SubmitChanges();
|
---|
750 | }
|
---|
751 | }
|
---|
752 |
|
---|
753 | public void RemoveUserGroupBaseFromGroup(DT.UserGroupBase resource, DT.UserGroup userGroup) {
|
---|
754 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
755 | var query = from u in context.UserGroupUserGroups
|
---|
756 | where u.UserGroupId == resource.Id && u.UserGroupUserGroupId == userGroup.Id
|
---|
757 | select u;
|
---|
758 |
|
---|
759 | if (query.Count() == 1) {
|
---|
760 | context.UserGroupUserGroups.DeleteOnSubmit(query.First());
|
---|
761 | context.SubmitChanges();
|
---|
762 | }
|
---|
763 | }
|
---|
764 | }
|
---|
765 |
|
---|
766 | public IEnumerable<DT.UserGroupBase> GetUsersAndGroups() {
|
---|
767 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
768 | var query = from u in context.UserGroupBases
|
---|
769 | select Convert.ToDto(u);
|
---|
770 | return query.ToList();
|
---|
771 | }
|
---|
772 | }
|
---|
773 |
|
---|
774 | public IEnumerable<DT.UserGroupMapping> GetUserGroupMapping() {
|
---|
775 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
776 | var query = from u in context.UserGroupUserGroups
|
---|
777 | select Convert.ToDto(u);
|
---|
778 | return query.ToList();
|
---|
779 | }
|
---|
780 | }
|
---|
781 |
|
---|
782 | public IEnumerable<Guid> GetUserGroupIdsOfGroup(Guid groupId) {
|
---|
783 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
784 | var query = from u in context.UserGroupUserGroups
|
---|
785 | where u.UserGroupUserGroupId == groupId
|
---|
786 | select u.UserGroupId;
|
---|
787 | return query.ToList();
|
---|
788 | }
|
---|
789 | }
|
---|
790 | #endregion
|
---|
791 |
|
---|
792 | #region UserGroupBase
|
---|
793 | public IEnumerable<DT.UserGroupBase> GetAllLeightweightUsersAndGroups() {
|
---|
794 | //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
|
---|
795 | List<DT.UserGroup> userGroups = new List<DT.UserGroup>();
|
---|
796 | List<DT.UserGroupBase> result = new List<DT.UserGroupBase>();
|
---|
797 |
|
---|
798 | // this is just for generating users from asp.net authenticaton db; we should maybe provide an updatescript instead
|
---|
799 | List<Guid> accessUserGuids = null;
|
---|
800 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
801 | var query = from u in context.aspnet_Users
|
---|
802 | select u.UserId;
|
---|
803 | accessUserGuids = query.ToList();
|
---|
804 | }
|
---|
805 | var lightweightUsers = accessUserGuids.Select(x => BuildLightweightUserDto(x));
|
---|
806 |
|
---|
807 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
808 | var query = from u in context.UserGroupBases.OfType<DA.UserGroup>()
|
---|
809 | select Convert.ToDto(u);
|
---|
810 | userGroups = query.ToList();
|
---|
811 | }
|
---|
812 |
|
---|
813 | result.AddRange(lightweightUsers);
|
---|
814 | result.AddRange(userGroups);
|
---|
815 |
|
---|
816 | return result;
|
---|
817 | }
|
---|
818 |
|
---|
819 | public IEnumerable<DT.UserGroupBase> GetLeightweightUsersAndGroups(IEnumerable<Guid> ids) {
|
---|
820 | List<DA.UserGroupBase> dbUserGroupsBases = new List<DA.UserGroupBase>();
|
---|
821 | List<DT.UserGroupBase> result = new List<DT.UserGroupBase>();
|
---|
822 |
|
---|
823 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
824 | var query = from u in context.UserGroupBases
|
---|
825 | where ids.Contains(u.Id)
|
---|
826 | select u;
|
---|
827 | dbUserGroupsBases = query.ToList();
|
---|
828 | }
|
---|
829 |
|
---|
830 | foreach (var ugb in dbUserGroupsBases) {
|
---|
831 | if (ugb.GetType() == typeof(DA.User)) {
|
---|
832 | var user = BuildLightweightUserDto(ugb.Id);
|
---|
833 | result.Add(user);
|
---|
834 | } else if (ugb.GetType() == typeof(DA.UserGroup)) {
|
---|
835 | var group = Convert.ToDto(ugb as DA.UserGroup);
|
---|
836 | result.Add(group);
|
---|
837 | }
|
---|
838 | }
|
---|
839 | return result;
|
---|
840 | }
|
---|
841 | #endregion
|
---|
842 |
|
---|
843 | #region Roles
|
---|
844 | public IEnumerable<DT.Role> GetRoles() {
|
---|
845 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
846 | var query = from u in context.aspnet_Roles
|
---|
847 | select Convert.ToDto(u);
|
---|
848 | return query.ToList();
|
---|
849 | }
|
---|
850 | }
|
---|
851 |
|
---|
852 | public DT.Role AddRole(DT.Role role) {
|
---|
853 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
854 |
|
---|
855 | Roles.CreateRole(role.Name);
|
---|
856 | return role;
|
---|
857 | }
|
---|
858 |
|
---|
859 | public void DeleteRole(DT.Role role) {
|
---|
860 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
861 |
|
---|
862 | Roles.DeleteRole(role.Name);
|
---|
863 | }
|
---|
864 |
|
---|
865 | public IEnumerable<DT.Role> GetUserRoles(DT.User user) {
|
---|
866 | var roles = Roles.GetRolesForUser(user.UserName);
|
---|
867 | return roles.Select(x => new DT.Role() { Name = x });
|
---|
868 | }
|
---|
869 |
|
---|
870 | public void AddRoleToGroup(DT.UserGroup userGroup, DT.Role role) {
|
---|
871 | Guid[] userIds;
|
---|
872 | string[] aspUsers;
|
---|
873 |
|
---|
874 | using (DA.AccessServiceDataContext accessContext = new DA.AccessServiceDataContext()) {
|
---|
875 | userIds = (from u in accessContext.UserGroupUserGroups
|
---|
876 | where u.UserGroupUserGroupId == userGroup.Id
|
---|
877 | select u.UserGroupId).ToArray();
|
---|
878 | }
|
---|
879 |
|
---|
880 | using (DA.ASPNETAuthenticationDataContext aspContext = new DA.ASPNETAuthenticationDataContext()) {
|
---|
881 | aspUsers = (from u in aspContext.aspnet_Users
|
---|
882 | where userIds.Contains(u.UserId)
|
---|
883 | select u.UserName).ToArray();
|
---|
884 | }
|
---|
885 |
|
---|
886 | Roles.AddUsersToRole(aspUsers, role.Name);
|
---|
887 |
|
---|
888 | }
|
---|
889 |
|
---|
890 | public void RemoveRoleFromGroup(DT.UserGroup userGroup, DT.Role role) {
|
---|
891 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
892 |
|
---|
893 | Guid[] userIds;
|
---|
894 | string[] aspUsers;
|
---|
895 |
|
---|
896 | using (DA.AccessServiceDataContext accessContext = new DA.AccessServiceDataContext()) {
|
---|
897 | userIds = (from u in accessContext.UserGroupUserGroups
|
---|
898 | where u.UserGroupUserGroupId == userGroup.Id
|
---|
899 | select u.UserGroupId).ToArray();
|
---|
900 | }
|
---|
901 |
|
---|
902 | using (DA.ASPNETAuthenticationDataContext aspContext = new DA.ASPNETAuthenticationDataContext()) {
|
---|
903 | aspUsers = (from u in aspContext.aspnet_Users
|
---|
904 | where userIds.Contains(u.UserId)
|
---|
905 | select u.UserName).ToArray();
|
---|
906 | }
|
---|
907 |
|
---|
908 | Roles.RemoveUsersFromRole(aspUsers.ToArray(), role.Name);
|
---|
909 | }
|
---|
910 | #endregion
|
---|
911 |
|
---|
912 | #region Error Reporting
|
---|
913 | public void ReportError(DT.ClientError error) {
|
---|
914 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
915 | context.ClientErrors.InsertOnSubmit(Convert.ToEntity(error));
|
---|
916 | context.SubmitChanges();
|
---|
917 | }
|
---|
918 | }
|
---|
919 |
|
---|
920 | public IEnumerable<DT.ClientError> GetClientErrors() {
|
---|
921 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
922 |
|
---|
923 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
924 | var query = from c in context.ClientErrors
|
---|
925 | select Convert.ToDto(c);
|
---|
926 | return query.ToList();
|
---|
927 | }
|
---|
928 | }
|
---|
929 |
|
---|
930 | public IEnumerable<DT.ClientError> GetLastClientErrors(DateTime startDate) {
|
---|
931 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
932 |
|
---|
933 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
934 | var query = from c in context.ClientErrors
|
---|
935 | where c.Timestamp >= startDate
|
---|
936 | select Convert.ToDto(c);
|
---|
937 | return query.ToList();
|
---|
938 | }
|
---|
939 | }
|
---|
940 |
|
---|
941 | public void DeleteError(DT.ClientError error) {
|
---|
942 | RoleVerifier.AuthenticateForAllRoles(AccessServiceRoles.Administrator);
|
---|
943 |
|
---|
944 | using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
|
---|
945 | var query = context.ClientErrors.Where(x => x.Id == error.Id);
|
---|
946 | if (query.Count() > 0) {
|
---|
947 | context.ClientErrors.DeleteOnSubmit(query.First());
|
---|
948 | context.SubmitChanges();
|
---|
949 | }
|
---|
950 | }
|
---|
951 | }
|
---|
952 | #endregion
|
---|
953 | }
|
---|
954 | }
|
---|