Ejemplo n.º 1
0
        public bool Logout(string sessionId)
        {
            int rowsDeleted = 0;

            using (UserSessionRepository userSessionRepository = new UserSessionRepository())
            {
                UserSession session = userSessionRepository.Find(x => x.SessionId == sessionId);
                if (session != null)
                {
                    rowsDeleted = userSessionRepository.Delete(session);
                }
                else
                {
                    _loggger.Error(string.Format("Session with session id {0} not found", sessionId));
                    throw new ApplicationException("Session not found.");
                }
            }
            return(rowsDeleted > 0);
        }
Ejemplo n.º 2
0
        public UserSessionDto GetUserSessionBySessionId(string sessionId)
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                return(null);
            }
            UserSession userSession = null;

            using (UserSessionRepository userSessionRepository = new UserSessionRepository())
            {
                userSession = userSessionRepository.Find(x => x.SessionId == sessionId);
            }
            if (userSession == null)
            {
                return(null);
            }
            else
            {
                UserInfo userInfo = new UserInfo();
                using (UserInfoRepository userInfoRepository = new UserInfoRepository())
                {
                    userInfo = userInfoRepository.Find(x => x.UserId == userSession.UserId);
                }
                if (userInfo != null)
                {
                    return(new UserSessionDto()
                    {
                        SessionId = sessionId,
                        User = new UserInfoDto()
                        {
                            FirstName = userInfo.FirstName,
                            LastName = userInfo.LastName,
                            Email = userInfo.EMail,
                            UserId = userInfo.UserId,
                            Gender = userInfo.Gender
                        }
                    });
                }
            }
            return(null);
        }