- Timestamp:
- 06/26/10 10:13:12 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabRoleProvider.cs
r3954 r3955 8 8 namespace Service.Provider { 9 9 class HeuristicLabRoleProvider : RoleProvider { 10 protected string applicationName; 11 10 12 public override void AddUsersToRoles(string[] usernames, string[] roleNames) { 11 throw new NotImplementedException(); 13 if (usernames != null && roleNames != null) { 14 Persistence.DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext(); 15 List<HeuristicLabUser> users = db.HeuristicLabUsers.Where(u => usernames.Contains(u.UserName)).ToList<HeuristicLabUser>(); 16 List<HeuristicLabRole> roles = db.HeuristicLabRole.Where(r => roleNames.Contains(r.RoleName)).ToList<HeuristicLabRole>(); 17 foreach (HeuristicLabUser user in users) { 18 foreach (HeuristicLabRole role in roles) { 19 HeuristicLabUserRole userRole = new HeuristicLabUserRole(); 20 userRole.HeuristicLabRole = role; 21 userRole.HeuristicLabUser = user; 22 23 db.HeuristicLabUserRole.InsertOnSubmit(userRole); 24 25 } 26 } 27 db.SubmitChanges(); 28 } 12 29 } 13 30 14 31 public override string ApplicationName { 15 32 get { 16 throw new NotImplementedException();33 return this.applicationName; 17 34 } 18 35 set { 19 th row new NotImplementedException();36 this.applicationName = value; 20 37 } 21 38 } … … 27 44 28 45 public virtual void CreateRole(String roleName, bool isPermission) { 29 Persistence.DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext(); 30 HeuristicLabRole role = new HeuristicLabRole(); 31 role.RoleName = roleName; 32 role.IsPermission = isPermission; 33 db.HeuristicLabRole.InsertOnSubmit(role); 34 db.SubmitChanges(); 46 if (roleName != null) { 47 Persistence.DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext(); 48 HeuristicLabRole role = new HeuristicLabRole(); 49 role.RoleName = roleName; 50 role.IsPermission = isPermission; 51 db.HeuristicLabRole.InsertOnSubmit(role); 52 db.SubmitChanges(); 53 } 35 54 } 36 55 … … 44 63 if (roleName != null && db.HeuristicLabRole.Count(r => r.RoleName == roleName) == 1) { 45 64 HeuristicLabRole role = db.HeuristicLabRole.Single(r => r.RoleName == roleName); 46 foreach(HeuristicLabUserRole userRole in role.HeuristicLabUserRole) 47 { 65 foreach (HeuristicLabUserRole userRole in role.HeuristicLabUserRole) { 48 66 if (userRole.HeuristicLabUser.UserName.Contains(usernameToMatch)) { 49 67 returnValue.Add(userRole.HeuristicLabUser.UserName); 50 68 } 51 69 } 52 70 } 53 71 db.Dispose(); 54 72 return returnValue.ToArray(); … … 59 77 60 78 List<HeuristicLabRole> roles = new List<HeuristicLabRole>(DatabaseUtil.createDataClassesDataContext().HeuristicLabRole.Select(r => r)); 61 foreach(HeuristicLabRole r in roles) 62 { 79 foreach (HeuristicLabRole r in roles) { 63 80 roleList.Add(r.RoleName); 64 81 } … … 71 88 DataClassesDataContext context = DatabaseUtil.createDataClassesDataContext(); 72 89 if (username != null && context.HeuristicLabUsers.Count(u => u.UserName == username) > 0) { 73 90 74 91 Persistence.HeuristicLabUser user = context.HeuristicLabUsers.Single(u => u.UserName == username); 75 92 foreach (Persistence.HeuristicLabUserRole userRole in user.HeuristicLabUserRole) {
Note: See TracChangeset
for help on using the changeset viewer.