예제 #1
0
        /// <summary>
        /// DeleteSignInTokensAsync
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="idiom"></param>
        /// <param name="logOffType"></param>
        /// <param name="lastUser"></param>
        /// <param name="transactionContext"></param>
        /// <returns></returns>
        /// <exception cref="DatabaseException"></exception>
        private async Task DeleteSignInTokensAsync(long userId, DeviceIdiom idiom, LogOffType logOffType, string lastUser, TransactionContext transactionContext)
        {
            IEnumerable <SignInToken> resultList = await _signInTokenRepo.GetByUserIdAsync(userId, transactionContext).ConfigureAwait(false);

            IEnumerable <SignInToken> toDeletes = logOffType switch
            {
                LogOffType.LogOffAllOthers => resultList,
                LogOffType.LogOffAllButWeb => resultList.Where(s => s.DeviceIdiom != DeviceIdiom.Web),
                LogOffType.LogOffSameIdiom => resultList.Where(s => s.DeviceIdiom == idiom),
                _ => new List <SignInToken>()
            };

            await _signInTokenRepo.DeleteAsync(toDeletes, lastUser, transactionContext).ConfigureAwait(false);
        }
예제 #2
0
        public async Task SignOutAsync(string userGuid, DeviceIdiom idiom, LogOffType logOffType, string lastUser)
        {
            TransactionContext transactionContext = await _transaction.BeginTransactionAsync <SignInToken>().ConfigureAwait(false);

            try
            {
                await _signInTokenBiz.DeleteByLogOffTypeAsync(userGuid, idiom, logOffType, lastUser, transactionContext).ConfigureAwait(false);

                await _transaction.CommitAsync(transactionContext).ConfigureAwait(false);
            }
            catch
            {
                await _transaction.RollbackAsync(transactionContext).ConfigureAwait(false);

                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// SignOutAsync
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="idiom"></param>
        /// <param name="logOffType"></param>
        /// <param name="lastUser"></param>
        /// <returns></returns>
        /// <exception cref="DatabaseException"></exception>
        public async Task SignOutAsync(long userId, DeviceIdiom idiom, LogOffType logOffType, string lastUser)
        {
            ThrowIf.NotLongId(userId, nameof(userId));

            TransactionContext transactionContext = await _transaction.BeginTransactionAsync <SignInToken>().ConfigureAwait(false);

            try
            {
                await DeleteSignInTokensAsync(userId, idiom, logOffType, lastUser, transactionContext).ConfigureAwait(false);

                await _transaction.CommitAsync(transactionContext).ConfigureAwait(false);
            }
            catch
            {
                await _transaction.RollbackAsync(transactionContext).ConfigureAwait(false);

                throw;
            }
        }
예제 #4
0
        public async Task DeleteByLogOffTypeAsync(string userGuid, DeviceIdiom currentIdiom, LogOffType logOffType, string lastUser, TransactionContext transactionContext)
        {
            ThrowIf.Empty(userGuid, nameof(userGuid));

            IEnumerable <SignInToken> resultList = await GetByUserGuidAsync(userGuid, transactionContext).ConfigureAwait(false);

            IEnumerable <SignInToken> toDeletes = logOffType switch
            {
                LogOffType.LogOffAllOthers => resultList,
                LogOffType.LogOffAllButWeb => resultList.Where(s => s.DeviceIdiom != DeviceIdiom.Web),
                LogOffType.LogOffSameIdiom => resultList.Where(s => s.DeviceIdiom == currentIdiom),
                _ => new List <SignInToken>()
            };

            await BatchDeleteAsync(toDeletes, lastUser, transactionContext).ConfigureAwait(false);
        }