示例#1
0
        /// <summary>
        /// Removes a given login
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="login">The login.</param>
        /// <returns></returns>
        /// <exception cref="KeyNotFoundException">All server responses other than Success.</exception>
        /// <exception cref="Exception">Any client error condition.</exception>
        public async Task RemoveLoginAsync(T user, UserLoginInfo login)
        {
            SessionBase session  = Session;
            bool        inUpdate = session.InUpdateTransaction;

            if (inUpdate == false)
            {
                if (session.InTransaction)
                {
                    session.Commit();
                }
                session.BeginUpdate();
            }
            string key = KeyFormats.GetKey(login.ProviderKey, user.Id);

            m_aspNetIdentity.AdapterMap.Remove(key);

            user.UserLoginIds.Remove(login);
            await Task.FromResult(m_aspNetIdentity.UserSet.Add(user));

            if (inUpdate == false)
            {
                session.Commit();
            }
        }
示例#2
0
        /// <summary>
        /// Adds the login to a user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="login">The login.</param>
        /// <returns></returns>
        /// <exception cref="KeyNotFoundException">All server responses other than Success.</exception>
        /// <exception cref="Exception">Any client error condition.</exception>
        public async Task AddLoginAsync(T user, UserLoginInfo login)
        {
            var adapter = new UserLoginInfoAdapter
            {
                LoginInfo = login,
                UserId    = user.Id
            };
            SessionBase session  = Session;
            bool        inUpdate = session.InUpdateTransaction;

            if (inUpdate == false)
            {
                if (session.InTransaction)
                {
                    session.Commit();
                }
                session.BeginUpdate();
            }
            var key = KeyFormats.GetKey(login.LoginProvider, login.ProviderKey);

            m_aspNetIdentity.AdapterMap.Add(key, adapter);

            user.UserLoginIds.Add(login);
            await Task.FromResult(m_aspNetIdentity.UserSet.Add(user));

            if (inUpdate == false)
            {
                session.Commit();
            }
        }
示例#3
0
        /// <summary>
        /// Finds the login.
        /// </summary>
        /// <param name="login">The login.</param>
        /// <returns></returns>
        public async Task <T> FindAsync(UserLoginInfo login)
        {
            SessionBase session = Session;

            if (session.InTransaction == false)
            {
                session.BeginRead();
            }
            var          key     = KeyFormats.GetKey(login.LoginProvider, login.ProviderKey);
            var          adapter = m_aspNetIdentity.AdapterMap[key];
            IdentityUser user    = new IdentityUser(adapter.UserId);

            if (m_aspNetIdentity.UserSet.TryGetKey(user, ref user))
            {
                return((T)await Task.FromResult(user));
            }
            return(null);
        }