Пример #1
0
 public override void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     _logger.Debug("{0}.{1}", nameof(GuRoleProvider), nameof(AddUsersToRoles));
     try
     {
         using (GuProviderContext context = new GuProviderContext())
         {
             foreach (var userName in usernames)
             {
                 foreach (var roleName in roleNames)
                 {
                     if (!context.NET_GU_PERFILUSUARIO.Any(pu => pu.NET_GU_AUTORIZACION.USUARIO == userName && pu.NET_GU_DESCRIPCIONPERFIL.DESCRIPCION == roleName))
                     {
                         var ud = context.NET_GU_AUTORIZACION.SingleOrDefault(a => a.USUARIO == userName);
                         var rd = context.NET_GU_DESCRIPCIONPERFIL.SingleOrDefault(b => b.DESCRIPCION == roleName);
                         if (ud == null || rd == null) throw new ArgumentException("Datos no validos");
                         context.NET_GU_PERFILUSUARIO.Add(new NET_GU_PERFILUSUARIO()
                         {
                             ID_USUARIO = ud.ID_USUARIO,
                             ID_PERFIL = rd.ID_PERFIL,
                             ID_ORGANISMO = 0,
                             FECHA_CREACION = DateTime.Now,
                             FECHA_MODIFICACION = DateTime.Now,
                             NOTAS = string.Empty
                         });
                         context.SaveChanges();
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         _logger.Error(e, "Error en AddUsersToRoles: ");
         throw;
     }
 }
Пример #2
0
 public override string[] GetAllRoles()
 {
     _logger.Debug("{0}.{1}", nameof(GuRoleProvider), nameof(GetAllRoles));
     try
     {
         using (GuProviderContext context = new GuProviderContext())
         {
             var r = context.NET_GU_DESCRIPCIONPERFIL.OrderBy(s => s.DESCRIPCION).Select(q => q.DESCRIPCION);
             return r.ToArray();
         }
     }
     catch (Exception e)
     {
         _logger.Error(e);
         throw;
     }
 }
Пример #3
0
 public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
 {
     _logger.Debug("{0}.{1}", nameof(GuRoleProvider), nameof(RemoveUsersFromRoles));
     try
     {
         using (GuProviderContext context = new GuProviderContext())
         {
             foreach (var userName in usernames)
             {
                 foreach (var roleName in roleNames)
                 {
                     var urd = context.NET_GU_PERFILUSUARIO.SingleOrDefault(pu => pu.NET_GU_AUTORIZACION.USUARIO == userName
                         && pu.NET_GU_DESCRIPCIONPERFIL.DESCRIPCION == roleName);
                     if (urd != null)
                     {
                         context.NET_GU_PERFILUSUARIO.Remove(urd);
                         context.SaveChanges();
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         _logger.Error(e, "Error en RemoveUsersFromRoles: ");
         throw;
     }
 }
Пример #4
0
 public override string[] GetRolesForUser(string username)
 {
     _logger.Debug("{0}.{1}: {2}", nameof(GuRoleProvider), nameof(GetRolesForUser), username);
     try
     {
         using (GuProviderContext context = new GuProviderContext())
         {
             var r = context.NET_GU_AUTORIZACION.Include(a => a.NET_GU_PERFILUSUARIO.Select(pp => pp.NET_GU_DESCRIPCIONPERFIL)).SingleOrDefault(a => a.USUARIO == username);
             var p = r.NET_GU_PERFILUSUARIO.Select(d => d.NET_GU_DESCRIPCIONPERFIL.DESCRIPCION).ToList();
             return p.ToArray();
         }
     }
     catch (Exception e)
     {
         _logger.Error(e, "Error en GetRolesForUser: ");
         throw;
     }
 }