Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/10 10:13:12 (14 years ago)
Author:
bfarka
Message:

created impl and test of AddUsersToRoles (#1046)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabRoleProvider.cs

    r3954 r3955  
    88namespace Service.Provider {
    99  class HeuristicLabRoleProvider : RoleProvider {
     10    protected string applicationName;
     11
    1012    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      }
    1229    }
    1330
    1431    public override string ApplicationName {
    1532      get {
    16         throw new NotImplementedException();
     33        return this.applicationName;
    1734      }
    1835      set {
    19         throw new NotImplementedException();
     36        this.applicationName = value;
    2037      }
    2138    }
     
    2744
    2845    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      }
    3554    }
    3655
     
    4463      if (roleName != null && db.HeuristicLabRole.Count(r => r.RoleName == roleName) == 1) {
    4564        HeuristicLabRole role = db.HeuristicLabRole.Single(r => r.RoleName == roleName);
    46         foreach(HeuristicLabUserRole userRole in role.HeuristicLabUserRole)
    47         {
     65        foreach (HeuristicLabUserRole userRole in role.HeuristicLabUserRole) {
    4866          if (userRole.HeuristicLabUser.UserName.Contains(usernameToMatch)) {
    4967            returnValue.Add(userRole.HeuristicLabUser.UserName);
    5068          }
    5169        }
    52        }
     70      }
    5371      db.Dispose();
    5472      return returnValue.ToArray();
     
    5977
    6078      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) {
    6380        roleList.Add(r.RoleName);
    6481      }
     
    7188      DataClassesDataContext context = DatabaseUtil.createDataClassesDataContext();
    7289      if (username != null && context.HeuristicLabUsers.Count(u => u.UserName == username) > 0) {
    73        
     90
    7491        Persistence.HeuristicLabUser user = context.HeuristicLabUsers.Single(u => u.UserName == username);
    7592        foreach (Persistence.HeuristicLabUserRole userRole in user.HeuristicLabUserRole) {
Note: See TracChangeset for help on using the changeset viewer.