diff Agendas/trunk/src/Agendas.Domain/IdentityContext.cs @ 179:1deccd6c3cb2

Aplicando seguridad x roles en sitio web
author nelopauselli
date Mon, 08 Aug 2011 15:24:26 -0300
parents 7a2eeb9e9bf9
children
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Domain/IdentityContext.cs	Mon Aug 08 12:30:37 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/IdentityContext.cs	Mon Aug 08 15:24:26 2011 -0300
@@ -1,4 +1,6 @@
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using AltNetHispano.Agendas.Domain.Exceptions;
 using AltNetHispano.Agendas.Domain.Repositories;
 
@@ -46,5 +48,17 @@
 			var cuenta = _personaRepository.GetCuenta(identification.IdentityProvider, identification.LogonName);
 			return cuenta != null ? cuenta.Persona : null;
 		}
+
+		public static bool IsInRole(IEnumerable<string> roles)
+		{
+			var persona = GetUsuario();
+			return IsInRole(persona, roles);
+		}
+
+		public static bool IsInRole(Persona persona, IEnumerable<string> roles)
+		{
+			if (persona == null) return false;
+			return roles.Any(role => persona.Roles.Contains(role));
+		}
 	}
 }
\ No newline at end of file