- Timestamp:
- 09/29/11 17:16:42 (13 years ago)
- Location:
- branches/ClientUserManagement/HeuristicLab.Services.Access/3.3
- Files:
-
- 1 added
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/AccessService.cs
r6840 r6852 24 24 using System.Linq; 25 25 using System.ServiceModel; 26 using System.Web.Security; 26 27 using DA = HeuristicLab.Services.Access.DataAccess; 27 28 using DT = HeuristicLab.Services.Access.DataTransfer; … … 30 31 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 31 32 public class AccessService : IAccessService { 33 private IUserManager userManager; 34 private IUserManager UserManager { 35 get { 36 if (userManager == null) userManager = new UserManager(); 37 return userManager; 38 } 39 } 32 40 33 41 #region Client Members … … 83 91 public void DeleteClient(DT.Client client) { 84 92 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 85 context.Resources.DeleteOnSubmit(Convert.ToEntity(client)); 86 context.SubmitChanges(); 93 //load client because we could get a detached object 94 var query = from c in context.GetTable<DA.Resource>().OfType<DA.Client>() 95 where c.Id == client.Id 96 select c; 97 if (query.Count() > 0) { 98 context.Resources.DeleteOnSubmit(query.First()); 99 context.SubmitChanges(); 100 } 87 101 } 88 102 } … … 120 134 } 121 135 122 public void DeleteClientGroup(DT.ClientGroup group) { 123 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 124 context.Resources.DeleteOnSubmit(Convert.ToEntity(group)); 125 context.SubmitChanges(); 126 } 127 } 128 129 public void AddResourceToGroup(DT.Resource resource, DT.UserGroup group) { 136 public void DeleteClientGroup(DT.ClientGroup clientGroup) { 137 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 138 //load clientGroup because we could get a detached object 139 var query = from c in context.GetTable<DA.Resource>().OfType<DA.ClientGroup>() 140 where c.Id == clientGroup.Id 141 select c; 142 if (query.Count() > 0) { 143 context.Resources.DeleteOnSubmit(query.First()); 144 context.SubmitChanges(); 145 } 146 } 147 } 148 149 public void AddResourceToGroup(DT.Resource resource, DT.ClientGroup group) { 130 150 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 131 151 DA.ResourceResourceGroup rrg = new DA.ResourceResourceGroup() { … … 139 159 } 140 160 141 public void RemoveResourceFromGroup(DT.Resource resource, DT. UserGroup group) {161 public void RemoveResourceFromGroup(DT.Resource resource, DT.ClientGroup group) { 142 162 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 143 163 var query = context.ResourceResourceGroups.Where(x => x.ResourceId == resource.Id && x.ResourceGroupId == group.Id); … … 214 234 215 235 #region User 236 private DT.User BuildUserDto(Guid userId) { 237 DA.aspnet_User aspUser = null; 238 DA.aspnet_Membership aspMembership = null; 239 DA.User accessUser = null; 240 241 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 242 var query = from u in context.UserGroupBases.OfType<DA.User>() 243 where u.Id == userId 244 select u; 245 if (query.Count() == 1) { 246 accessUser = query.First(); 247 } 248 } 249 250 using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) { 251 var userQuery = from u in context.aspnet_Users 252 where u.UserId == userId 253 select u; 254 if (userQuery.Count() == 1) { 255 aspUser = userQuery.First(); 256 } 257 258 var memQuery = from u in context.aspnet_Memberships 259 where u.UserId == userId 260 select u; 261 if (memQuery.Count() == 1) { 262 aspMembership = memQuery.First(); 263 } 264 } 265 266 if (aspUser == null || aspMembership == null || accessUser == null) { 267 //TODO: error handling 268 return null; 269 } else { 270 return Convert.ToDto(accessUser, aspUser, aspMembership); 271 } 272 } 273 216 274 public DT.User Login() { 217 throw new System.NotImplementedException(); 275 Guid userId = UserManager.CurrentUserId; 276 return BuildUserDto(userId); 218 277 } 219 278 220 279 public IEnumerable<DT.User> GetAllUsers() { 221 throw new System.NotImplementedException(); 222 } 223 224 public IEnumerable<DT.User> GetUsers(IEnumerable<DT.User> ids) { 225 throw new System.NotImplementedException(); 280 List<Guid> accessUserGuids = null; 281 282 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 283 var query = from u in context.UserGroupBases.OfType<DA.User>() 284 select u.Id; 285 accessUserGuids = query.ToList(); 286 } 287 288 return accessUserGuids.Select(x => BuildUserDto(x)); 289 } 290 291 public IEnumerable<DT.User> GetUsers(IEnumerable<Guid> ids) { 292 List<Guid> accessUserGuids = null; 293 294 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 295 var query = from u in context.UserGroupBases.OfType<DA.User>() 296 where ids.Contains(u.Id) 297 select u.Id; 298 accessUserGuids = query.ToList(); 299 } 300 301 return accessUserGuids.Select(x => BuildUserDto(x)); 226 302 } 227 303 228 304 public DT.User AddUser(DT.User user) { 229 throw new System.NotImplementedException(); 305 DA.User accessUser; 306 DA.aspnet_User aspUser; 307 DA.aspnet_Membership aspMembership; 308 bool userExistsInASP; 309 310 Convert.ToEntity(user, out accessUser, out aspUser, out aspMembership, out userExistsInASP); 311 312 if (userExistsInASP) { 313 if (accessUser.Id == null || accessUser.Id == Guid.Empty) { 314 accessUser.Id = aspMembership.UserId; 315 } 316 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 317 context.UserGroupBases.InsertOnSubmit(accessUser); 318 context.SubmitChanges(); 319 } 320 MembershipUser membershipUser = Membership.GetUser((object)accessUser.Id); 321 if (membershipUser != null) { 322 membershipUser.Email = aspMembership.Email; 323 membershipUser.IsApproved = aspMembership.IsApproved; 324 membershipUser.Comment = aspMembership.Comment; 325 Membership.UpdateUser(membershipUser); 326 } 327 } else { 328 MembershipUser membershipUser = Membership.CreateUser(aspUser.UserName, aspUser.UserName, aspMembership.Email); 329 membershipUser.IsApproved = aspMembership.IsApproved; 330 membershipUser.Comment = aspMembership.Comment; 331 Membership.UpdateUser(membershipUser); 332 333 Guid userId = (Guid)membershipUser.ProviderUserKey; 334 accessUser.Id = userId; 335 336 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 337 context.UserGroupBases.InsertOnSubmit(accessUser); 338 context.SubmitChanges(); 339 } 340 } 341 342 using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) { 343 var newAspUser = context.aspnet_Users.Where(x => x.UserId == accessUser.Id).FirstOrDefault(); 344 var newAspMembership = context.aspnet_Memberships.Where(x => x.UserId == accessUser.Id).FirstOrDefault(); 345 return Convert.ToDto(accessUser, newAspUser, newAspMembership); 346 } 230 347 } 231 348 232 349 public void DeleteUser(DT.User user) { 233 throw new System.NotImplementedException(); 350 if (user.Id != null && user.Id != Guid.Empty) { 351 Membership.DeleteUser(user.UserName); 352 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 353 context.UserGroupBases.DeleteOnSubmit(Convert.ToEntity(user)); 354 context.SubmitChanges(); 355 } 356 } 234 357 } 235 358 236 359 public void UpdateUser(DT.User user) { 237 throw new System.NotImplementedException();360 AddUser(user); 238 361 } 239 362 240 363 public void AddUserToRole(DT.Role role, DT.User user) { 241 throw new System.NotImplementedException(); 364 //TODO: usernames and rolenames have to be unique! 365 MembershipUser msUser = Membership.GetUser((object)user.Id); 366 if (msUser != null) { 367 Roles.AddUserToRole(msUser.UserName, role.Name); 368 } 242 369 } 243 370 244 371 public void RemoveUserFromRole(DT.Role role, DT.User user) { 245 throw new System.NotImplementedException(); 246 } 247 248 public void ResetPassword(DT.User user, string password) { 249 throw new System.NotImplementedException(); 250 } 251 #endregion 252 372 MembershipUser msUser = Membership.GetUser((object)user.Id); 373 if (msUser != null) { 374 Roles.RemoveUserFromRole(msUser.UserName, role.Name); 375 } 376 } 377 378 public bool ResetPassword(DT.User user, string oldPassword, string newPassword) { 379 MembershipUser msUser = Membership.GetUser((object)user.Id); 380 if (msUser != null) { 381 return msUser.ChangePassword(oldPassword, newPassword); 382 } 383 return false; 384 } 385 #endregion 386 387 #region UserGroup 253 388 public IEnumerable<DT.UserGroup> GetAllUserGroups() { 254 throw new System.NotImplementedException(); 389 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 390 var query = from u in context.UserGroupBases.OfType<DA.UserGroup>() 391 select Convert.ToDto(u); 392 return query.ToList(); 393 } 255 394 } 256 395 257 396 public IEnumerable<DT.UserGroup> GetUserGroups(IEnumerable<Guid> ids) { 258 throw new System.NotImplementedException(); 259 } 260 261 public DT.UserGroup AddUserGroup(DT.UserGroup group) { 262 throw new System.NotImplementedException(); 397 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 398 var query = from u in context.UserGroupBases.OfType<DA.UserGroup>() 399 where ids.Contains(u.Id) 400 select Convert.ToDto(u); 401 return query.ToList(); 402 } 403 } 404 405 public Guid AddUserGroup(DT.UserGroup group) { 406 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 407 context.UserGroupBases.InsertOnSubmit(Convert.ToEntity(group)); 408 context.SubmitChanges(); 409 return group.Id; 410 } 263 411 } 264 412 265 413 public void UpdateUserGroup(DT.UserGroup group) { 266 throw new System.NotImplementedException();414 AddUserGroup(group); 267 415 } 268 416 269 417 public void DeleteUserGroup(DT.UserGroup group) { 270 throw new System.NotImplementedException(); 418 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 419 context.UserGroupBases.DeleteOnSubmit(Convert.ToEntity(group)); 420 context.SubmitChanges(); 421 } 271 422 } 272 423 273 424 public void AddUserGroupBaseToGroup(DT.UserGroupBase resource, DT.UserGroup group) { 274 throw new System.NotImplementedException(); 275 } 276 277 public void RemoveUserGroupBaseFromGroup(DT.UserGroupBase resource, DT.UserGroup group) { 278 throw new System.NotImplementedException(); 425 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 426 DA.UserGroupUserGroup ugug = new DA.UserGroupUserGroup(); 427 ugug.UserGroupId = resource.Id; 428 ugug.UserGroupUserGroupId = group.Id; 429 context.UserGroupUserGroups.InsertOnSubmit(ugug); 430 context.SubmitChanges(); 431 } 432 } 433 434 public void RemoveUserGroupBaseFromGroup(DT.UserGroupBase resource, DT.UserGroup userGroup) { 435 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 436 var query = from u in context.UserGroupUserGroups 437 where u.UserGroupId == resource.Id && u.UserGroupUserGroupId == userGroup.Id 438 select u; 439 440 if (query.Count() == 1) { 441 context.UserGroupUserGroups.DeleteOnSubmit(query.First()); 442 context.SubmitChanges(); 443 } 444 } 279 445 } 280 446 281 447 public IEnumerable<DT.UserGroupBase> GetUsersAndGroups() { 282 throw new System.NotImplementedException(); 448 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 449 var query = from u in context.UserGroupBases 450 select Convert.ToDto(u); 451 return query.ToList(); 452 } 283 453 } 284 454 285 455 public IEnumerable<DT.UserGroupMapping> GetUserGroupMapping() { 286 throw new System.NotImplementedException(); 287 } 288 456 using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) { 457 var query = from u in context.UserGroupUserGroups 458 select Convert.ToDto(u); 459 return query.ToList(); 460 } 461 } 462 #endregion 463 464 #region Roles 289 465 public IEnumerable<DT.Role> GetRoles() { 290 466 throw new System.NotImplementedException(); … … 306 482 throw new System.NotImplementedException(); 307 483 } 308 484 #endregion 485 486 #region Error Reporting 309 487 public void ReportError(DT.ClientError error) { 310 488 throw new System.NotImplementedException(); … … 322 500 throw new System.NotImplementedException(); 323 501 } 502 #endregion 324 503 } 325 504 } -
branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/Convert.cs
r6840 r6852 68 68 #region Country 69 69 public static DT.Country ToDto(DA.Country source) { 70 return new DT.Country() { 71 Id = source.Id, 72 Name = source.Name 73 }; 70 if (source == null) { 71 return null; 72 } else { 73 return new DT.Country() { 74 Id = source.Id, 75 Name = source.Name 76 }; 77 } 74 78 } 75 79 76 80 public static DA.Country ToEntity(DT.Country source) { 77 return new DA.Country() { 78 Id = source.Id, 79 Name = source.Name, 80 81 }; 81 if (source == null) { 82 return null; 83 } else { 84 return new DA.Country() { 85 Id = source.Id, 86 Name = source.Name, 87 88 }; 89 } 82 90 } 83 91 #endregion … … 85 93 #region OperatingSystem 86 94 public static DT.OperatingSystem ToDto(DA.OperatingSystem source) { 87 return new DT.OperatingSystem() { 88 Id = source.Id, 89 Name = source.Name 90 }; 95 if (source == null) { 96 return null; 97 } else { 98 return new DT.OperatingSystem() { 99 Id = source.Id, 100 Name = source.Name 101 }; 102 } 91 103 } 92 104 93 105 public static DA.OperatingSystem ToEntity(DT.OperatingSystem source) { 94 return new DA.OperatingSystem() { 95 Id = source.Id, 96 Name = source.Name, 97 }; 106 if (source == null) { 107 return null; 108 } else { 109 return new DA.OperatingSystem() { 110 Id = source.Id, 111 Name = source.Name, 112 }; 113 } 98 114 } 99 115 #endregion … … 101 117 #region ClientType 102 118 public static DT.ClientType ToDto(DA.ClientType source) { 103 return new DT.ClientType() { 104 Id = source.Id, 105 Name = source.Name 106 }; 119 if (source == null) { 120 return null; 121 } else { 122 return new DT.ClientType() { 123 Id = source.Id, 124 Name = source.Name 125 }; 126 } 107 127 } 108 128 109 129 public static DA.ClientType ToEntity(DT.ClientType source) { 110 return new DA.ClientType() { 111 Id = source.Id, 112 Name = source.Name, 113 114 }; 130 if (source == null) { 131 return null; 132 } else { 133 return new DA.ClientType() { 134 Id = source.Id, 135 Name = source.Name, 136 137 }; 138 } 115 139 } 116 140 #endregion … … 118 142 #region ClientConfiguration 119 143 public static DT.ClientConfiguration ToDto(DA.ClientConfiguration source) { 120 return new DT.ClientConfiguration() { 121 Id = source.Id, 122 Hash = source.Hash, 123 Description = source.Description 124 }; 144 if (source == null) { 145 return null; 146 } else { 147 return new DT.ClientConfiguration() { 148 Id = source.Id, 149 Hash = source.Hash, 150 Description = source.Description 151 }; 152 } 125 153 } 126 154 127 155 public static DA.ClientConfiguration ToEntity(DT.ClientConfiguration source) { 128 return new DA.ClientConfiguration() { 129 Id = source.Id, 130 Hash = source.Hash, 131 Description = source.Description 132 }; 156 if (source == null) { 157 return null; 158 } else { 159 return new DA.ClientConfiguration() { 160 Id = source.Id, 161 Hash = source.Hash, 162 Description = source.Description 163 }; 164 } 133 165 } 134 166 #endregion … … 264 296 UserName = aspUserSource.UserName 265 297 }; 298 } 299 300 public static DA.User ToEntity(DT.User source) { 301 return new DA.User() { Id = source.Id, FullName = source.FullName }; 266 302 } 267 303 … … 302 338 303 339 #region ClientGroupMapping 304 public static DT.ClientGroupMapping ToDto(DA.ResourceResourceGroup c) {340 public static DT.ClientGroupMapping ToDto(DA.ResourceResourceGroup source) { 305 341 return new DT.ClientGroupMapping() { 306 Child = c.ResourceId, Parent = c.ResourceGroupId 307 }; 308 } 309 #endregion 310 311 342 Child = source.ResourceId, Parent = source.ResourceGroupId 343 }; 344 } 345 #endregion 346 347 #region UserGroupBase 348 public static DT.UserGroupBase ToDto(DA.UserGroupBase source) { 349 return new DT.UserGroupBase() { 350 Id = source.Id 351 }; 352 } 353 #endregion 354 355 #region UserGroupMapping 356 public static DT.UserGroupMapping ToDto(DA.UserGroupUserGroup source) { 357 return new DT.UserGroupMapping() { 358 Child = source.UserGroupId, Parent = source.UserGroupUserGroupId 359 }; 360 } 361 #endregion 312 362 } 313 363 } -
branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/HeuristicLab.Services.Access-3.3.csproj
r6840 r6852 48 48 <Reference Include="System.Runtime.Serialization" /> 49 49 <Reference Include="System.ServiceModel" /> 50 <Reference Include="System.Web" /> 51 <Reference Include="System.Web.ApplicationServices" /> 50 52 <Reference Include="System.Xml" /> 51 53 <Reference Include="System.Xml.Linq" /> … … 71 73 <Compile Include="DataTransfer\UserGroupMapping.cs" /> 72 74 <Compile Include="IAccessService.cs" /> 75 <Compile Include="Interfaces\IUserManager.cs" /> 73 76 <Compile Include="Properties\AssemblyInfo.cs" /> 74 77 <Compile Include="AccessService.cs" /> 78 <Compile Include="UserManager.cs" /> 75 79 </ItemGroup> 76 80 <ItemGroup> -
branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/IAccessService.cs
r6840 r6852 70 70 71 71 [OperationContract] 72 void AddResourceToGroup(Resource resource, UserGroup group);72 void AddResourceToGroup(Resource resource, ClientGroup group); 73 73 74 74 [OperationContract] 75 void RemoveResourceFromGroup(Resource resource, UserGroup group);75 void RemoveResourceFromGroup(Resource resource, ClientGroup group); 76 76 #endregion 77 77 … … 111 111 112 112 [OperationContract] 113 IEnumerable<User> GetUsers(IEnumerable< User> ids);113 IEnumerable<User> GetUsers(IEnumerable<Guid> ids); 114 114 115 115 [OperationContract] … … 129 129 130 130 [OperationContract] 131 void ResetPassword(User user, string password);131 bool ResetPassword(User user, string oldPassword, string newPassword); 132 132 #endregion 133 133 … … 140 140 141 141 [OperationContract] 142 UserGroupAddUserGroup(UserGroup group);142 Guid AddUserGroup(UserGroup group); 143 143 144 144 [OperationContract] -
branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/Interfaces/IUserManager.cs
r6822 r6852 23 23 using System.Web.Security; 24 24 25 namespace HeuristicLab.Services. Hive{25 namespace HeuristicLab.Services.Access { 26 26 public interface IUserManager { 27 27 MembershipUser CurrentUser { get; } -
branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/UserManager.cs
r6822 r6852 23 23 using System.Web.Security; 24 24 25 namespace HeuristicLab.Services. Hive{25 namespace HeuristicLab.Services.Access { 26 26 public class UserManager : IUserManager { 27 27 public MembershipUser CurrentUser {
Note: See TracChangeset
for help on using the changeset viewer.