Beispiel #1
0
 public IRole GetRoleInternal(String roleName, bool throwIfNotExists)
 {
     IRole result = null;
     roleName = roleName.ToLower();
     if (!_roles.TryGetValue(roleName, out result))
     {
         var qry = _store.CreateQuery<RoleModel>();
         qry.AddFilterEqual("RoleName", roleName);
         var model = qry.FindFirst();
         if (model != null)
         {
             result = new RoleImpl(model);
             _roles[roleName] = result;
         }
     }
     if (result == null && throwIfNotExists)
         throw new InvalidOperationException(String.Format("Não existe um papel com o nome " + roleName));
     return result;
 }
Beispiel #2
0
 public IRole[] GetRoles()
 {
     if (!_allRolesLoaded)
     {
         Sync(() =>
         {
             if (_allRolesLoaded)
                 return;
             _allRolesLoaded = true;
             var qry = _store.CreateQuery<RoleModel>();
             var roles = qry.Find();
             IRole role = null;
             foreach (var roleModel in roles)
             {
                 if (!_roles.TryGetValue(roleModel.RoleName.ToLower(), out role))
                 {
                     role = new RoleImpl(roleModel);
                     _roles[role.Name.ToLower()] = role;
                 }
             }
         });
     }
     return _roles.Values.OrderBy(r => r.Name).ToArray();
 }
Beispiel #3
0
 public IRole CreateRole(string roleName, string group)
 {
     Assert.EmptyString(roleName, "roleName");
     IRole role = null;
     Sync(() =>
     {
         role = GetRoleInternal(roleName, false);
         if (role == null)
         {
             var model = new RoleModel()
             {
                 RoleName = roleName,
                 GroupName = group
             };
             if (_store.Save(model))
             {
                 role = new RoleImpl(model);
                 _roles[roleName.ToLower()] = role;
             }
             else
                 throw new Exception("Não foi possivel criar o esquema de usuários - erro ao persistir as informações");
         }
         else
             throw new Exception("Já existe um papel com o nome " + roleName);
     });
     return role;
 }