/// <summary> /// Create or merge auth session. /// </summary> /// <param name="authSession">The auth session.</param> /// <param name="tokens">The tokens.</param> /// <returns>The <see cref="IUserAuthDetails"/>.</returns> public IUserAuthDetails CreateOrMergeAuthSession(IAuthSession authSession, IAuthTokens tokens) { // Try and get from the UserAuth table var userAuth = (LightSpeed.UserAuth) this.GetUserAuth(authSession, tokens); if (userAuth == null) { userAuth = new LightSpeed.UserAuth(); this.unitOfWork.Add(userAuth); } // Try and get from the OAuth table var oauthProvider = this.GetUserAuthDetailsByProvider(tokens.UserId, tokens.Provider) as UserAuthDetail; if (oauthProvider == null) { oauthProvider = new LightSpeed.UserAuthDetail { UserId = tokens.UserId, Provider = tokens.Provider }; this.unitOfWork.Add(oauthProvider); } oauthProvider.PopulateMissing(tokens); // Update UserAuth userAuth.PopulateMissingExtended(oauthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) { userAuth.CreatedDate = userAuth.ModifiedDate; } // Update UserAuthDetail oauthProvider.ModifiedDate = userAuth.ModifiedDate; if (oauthProvider.CreatedDate == default(DateTime)) { oauthProvider.CreatedDate = userAuth.ModifiedDate; } this.unitOfWork.SaveChanges(); return(oauthProvider); }
/// <summary> /// Create or merge auth session. /// </summary> /// <param name="authSession">The auth session.</param> /// <param name="tokens">The tokens.</param> /// <returns>The <see cref="IUserAuthDetails"/>.</returns> public IUserAuthDetails CreateOrMergeAuthSession(IAuthSession authSession, IAuthTokens tokens) { // Try and get from the UserAuth table var userAuth = (LightSpeed.UserAuth)this.GetUserAuth(authSession, tokens); if (userAuth == null) { userAuth = new LightSpeed.UserAuth(); this.unitOfWork.Add(userAuth); } // Try and get from the OAuth table var oauthProvider = this.GetUserAuthDetailsByProvider(tokens.UserId, tokens.Provider) as UserAuthDetail; if (oauthProvider == null) { oauthProvider = new LightSpeed.UserAuthDetail { UserId = tokens.UserId, Provider = tokens.Provider }; this.unitOfWork.Add(oauthProvider); } oauthProvider.PopulateMissing(tokens); // Update UserAuth userAuth.PopulateMissingExtended(oauthProvider); userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) { userAuth.CreatedDate = userAuth.ModifiedDate; } // Update UserAuthDetail oauthProvider.ModifiedDate = userAuth.ModifiedDate; if (oauthProvider.CreatedDate == default(DateTime)) { oauthProvider.CreatedDate = userAuth.ModifiedDate; } this.unitOfWork.SaveChanges(); return oauthProvider; }