public async Task <UserSession> GetUserSession()
        {
            _log.Info("Start getting session.");

            var id = GetIdFromCookie();

            if (string.IsNullOrWhiteSpace(id))
            {
                _log.Warning("Session id not found in cookie!");
                return(null);
            }

            _log.Info("Session found in cookie. Id:{Id}", id);

            var session = await _userSessionRepository.GetAsync(id);

            if (session == null)
            {
                _log.Warning("Session not found in database! Id:{Id}", id);
            }

            _log.Info("Session found in database. Id:{Id}", id);

            return(session);
        }
        private async Task <IActionResult> GetTokenBasedOnCookie(string sessionId)
        {
            if (sessionId == null)
            {
                return(Unauthorized());
            }

            var session = await _userSessionRepository.GetAsync(sessionId);

            var oldLykkeToken = session.Get <string>("OldLykkeToken");

            if (oldLykkeToken == null)
            {
                return(Unauthorized());
            }

            var lykkeClientId = session.Get <string>("LykkeClientId");

            var clientAccount = await _clientAccountClient.GetByIdAsync(lykkeClientId);

            var authId = session.Get <string>("AuthId");

            return(new JsonResult(new
            {
                token = oldLykkeToken,
                authId = authId,
                notificationsId = clientAccount.NotificationsId
            }));
        }
        public async Task <bool> Logout(int sessionId)
        {
            var session = await _repository.GetAsync(sessionId);

            if (session == null)
            {
                return(false);
            }

            session.Logout_DateTime = DateTime.Now;
            return(await _repository.UpdateAsync(session));
        }