private static void UpdateUserUiCulture(HttpRequestBase request, string uiCulture, IIdentity userIdentity) { //Andriy: Difficult to test this method, not fully clear how to correct inject database access in this code string aspNetUserId = userIdentity.GetUserId(); //Update user Ui Culture in database var db = request.GetOwinContext().Get <HellolingoEntities>(); AspNetUser user = db.AspNetUsers.Find(aspNetUserId); if (user == null) { Log.Warn(LogTag.CultureAwareActivator_UserNotFound, request, new { AspNetUserId = aspNetUserId }); return; } user.UiCulture = uiCulture; db.SaveChanges(); //Update user claims with new Ui Culture. var signInManager = request.GetOwinContext().Get <ApplicationSignInManager>(); signInManager.AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); var applicationUserManager = request.GetOwinContext().GetUserManager <ApplicationUserManager>(); ClaimsIdentity newUserIdentity = user.GenerateUserIdentity(applicationUserManager); signInManager.AuthenticationManager.SignIn(newUserIdentity); }