Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Domain/IdentityContext.cs @ 118:b74734a1a755
Manejo de eventos por estado
author | Nelo@Kenia.neluz.int |
---|---|
date | Wed, 22 Jun 2011 09:32:59 -0300 |
parents | 7a2eeb9e9bf9 |
children | 1deccd6c3cb2 |
line wrap: on
line source
using System; using AltNetHispano.Agendas.Domain.Exceptions; using AltNetHispano.Agendas.Domain.Repositories; namespace AltNetHispano.Agendas.Domain { public class IdentityContext { private static ISeguridad _current; private static IPersonaRepository _personaRepository; public static void Init(ISeguridad seguridad, IPersonaRepository personaRepository) { _current = seguridad; _personaRepository = personaRepository; } private static ISeguridad Current { get { if (_current == null) throw new IdentityContextNotConfiguredException(); return _current; } } public static string GetUserName() { return Current.GetUserName(); } public static bool IsAuthenticated() { return !string.IsNullOrWhiteSpace(GetUserName()); } public static Persona GetUsuario() { var userName = GetUserName(); if (string.IsNullOrWhiteSpace(userName)) throw new UsuarioNoAutenticadoException(); var identification = new Identification(userName); var cuenta = _personaRepository.GetCuenta(identification.IdentityProvider, identification.LogonName); return cuenta != null ? cuenta.Persona : null; } } }