private void SetUserContext(int?userId) { UserContext cx = null; if (userId.HasValue) { // Raw query required here because using IQueryExecutor will cause a stack overflow var dbResult = _dbContext .Users .AsNoTracking() .FilterById(userId.Value) .FilterCanLogIn() .SingleOrDefault(); if (dbResult == null) { // User no longer valid _userSessionService.Abandon(); ClearCache(); } else { cx = _userContextMapper.Map(dbResult); } } if (cx == null) { cx = new UserContext(); } _userContext = cx; _isUserContextCached = true; }
/// <summary> /// Signs the user out of the application and ends the session. /// </summary> public void SignOut() { _userSessionService.Abandon(); _userContextService.ClearCache(); }