﻿using System;
using System.Linq;
using Starcounter;
using Starcounter.Linq;

namespace People
{
    public class SessionHelper
    {
        public static SystemUserSession GetCurrentSystemUserSession()
        {
            string sessionId = Session.Current?.SessionId;
            DateTime now = DateTime.UtcNow;

            if (string.IsNullOrEmpty(sessionId))
            {
                return null;
            }

            SystemUserSession session = DbLinq.Objects<SystemUserSession>().FirstOrDefault(x => x.SessionId == sessionId && x.ExpiresAt > now);

            return session;
        }
    }
}
