Example #1
0
        public async Task <bool> LogAsync(int tokenId)
        {
            if (tokenId <= 0)
            {
                return(false);
            }

            var token = await _unitOfWork.AccessTokensRepository.GetByIdAsync(tokenId);

            if (token == null)
            {
                return(false);
            }

            var newLog = new AccessTokenLog
            {
                AccessTokenEntity     = token,
                ApiAccessUsersTokenId = tokenId,
                RequestDateTime       = DateTime.Now
            };

            await _unitOfWork.AccessTokensLogsRepository.AddAsync(newLog);

            return(await _unitOfWork.SaveChangesAsync() > 0);
        }
Example #2
0
        // 64 - length of the tokenEntity
        public async Task <bool> LogAsync(string token)
        {
            if (token == null ||
                token.Length != 64)
            {
                _logger.LogWarning(token is null
                                       ? $"{nameof(AccessTokensLogsService)}: Log: tokenEntity was null"
                                       : $"{nameof(AccessTokensLogsService)}: Log: tokenEntity was with incorrect length! (length: {token.Length})");

                return(false);
            }

            var tokenEntity = await _unitOfWork.AccessTokensRepository.GetByTokenAsync(token);

            if (tokenEntity == null)
            {
                _logger.LogWarning($"{nameof(AccessTokensLogsService)}: Log: {nameof(tokenEntity)} was not found in database");

                return(false);
            }

            var newLog = new AccessTokenLog
            {
                AccessTokenEntity     = tokenEntity,
                ApiAccessUsersTokenId = tokenEntity.Id,
                RequestDateTime       = DateTime.Now
            };

            await _unitOfWork.AccessTokensLogsRepository.AddAsync(newLog);

            return(await _unitOfWork.SaveChangesAsync() > 0);
        }