Пример #1
0
        public IUserAuthDetails CreateOrMergeAuthSession(IAuthSession authSession, IAuthTokens tokens)
        {
            var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuthNHibernate();

            using (var nhSession = GetCurrentSessionFn(sessionFactory))
            {
                var authDetails = nhSession.QueryOver <UserAuthDetailsNHibernate>()
                                  .Where(x => x.Provider == tokens.Provider)
                                  .And(x => x.UserId == tokens.UserId)
                                  .SingleOrDefault();

                if (authDetails == null)
                {
                    authDetails = new UserAuthDetailsNHibernate
                    {
                        Provider = tokens.Provider,
                        UserId   = tokens.UserId,
                    };
                }

                authDetails.PopulateMissing(tokens);
                userAuth.PopulateMissingExtended(authDetails);

                userAuth.ModifiedDate = DateTime.UtcNow;
                if (userAuth.CreatedDate == default(DateTime))
                {
                    userAuth.CreatedDate = userAuth.ModifiedDate;
                }

                nhSession.Save(userAuth);

                authDetails.UserAuthId = userAuth.Id;

                if (authDetails.CreatedDate == default(DateTime))
                {
                    authDetails.CreatedDate = userAuth.ModifiedDate;
                }
                authDetails.ModifiedDate = userAuth.ModifiedDate;

                nhSession.Save(authDetails);

                return(authDetails);
            }
        }
Пример #2
0
        public string CreateOrMergeAuthSession(IAuthSession authSession, IAuthTokens tokens)
        {
            var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuthNHibernate();

            var oAuthProvider = Session.QueryOver <UserAuthDetailsNHibernate>()
                                .Where(x => x.Provider == tokens.Provider)
                                .And(x => x.UserId == tokens.UserId)
                                .SingleOrDefault();

            if (oAuthProvider == null)
            {
                oAuthProvider = new UserAuthDetailsNHibernate {
                    Provider = tokens.Provider,
                    UserId   = tokens.UserId,
                };
            }

            oAuthProvider.PopulateMissing(tokens);
            userAuth.PopulateMissingExtended(oAuthProvider);

            userAuth.ModifiedDate = DateTime.UtcNow;
            if (userAuth.CreatedDate == default(DateTime))
            {
                userAuth.CreatedDate = userAuth.ModifiedDate;
            }

            Session.Save(userAuth);

            oAuthProvider.UserAuthId = userAuth.Id;

            if (oAuthProvider.CreatedDate == default(DateTime))
            {
                oAuthProvider.CreatedDate = userAuth.ModifiedDate;
            }
            oAuthProvider.ModifiedDate = userAuth.ModifiedDate;

            Session.Save(oAuthProvider);

            return(oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture));
        }