public async Task <IEnumerable <Cipher> > GetAllAsync()
        {
            if (!_deviceInfoService.IsExtension && _appSettingsService.ClearCiphersCache)
            {
                CachedCiphers = null;
                _appSettingsService.ClearCiphersCache = false;
            }

            if (_deviceInfoService.IsExtension && _appSettingsService.ClearExtensionCiphersCache)
            {
                CachedCiphers = null;
                _appSettingsService.ClearExtensionCiphersCache = false;
            }

            if (CachedCiphers != null)
            {
                return(CachedCiphers);
            }

            var attachmentData = await _attachmentRepository.GetAllByUserIdAsync(_authService.UserId);

            var attachmentDict = attachmentData.GroupBy(a => a.LoginId).ToDictionary(g => g.Key, g => g.ToList());
            var data           = await _cipherRepository.GetAllByUserIdAsync(_authService.UserId);

            CachedCiphers = data
                            .Select(f => new Cipher(f, attachmentDict.ContainsKey(f.Id) ? attachmentDict[f.Id] : null))
                            .ToList();
            return(CachedCiphers);
        }
Esempio n. 2
0
        public async Task <IEnumerable <Cipher> > GetAllAsync()
        {
            if (CachedCiphers != null)
            {
                return(CachedCiphers);
            }

            var attachmentData = await _attachmentRepository.GetAllByUserIdAsync(_authService.UserId);

            var attachmentDict = attachmentData.GroupBy(a => a.LoginId).ToDictionary(g => g.Key, g => g.ToList());
            var data           = await _cipherRepository.GetAllByUserIdAsync(_authService.UserId);

            CachedCiphers = data
                            .Select(f => new Cipher(f, attachmentDict.ContainsKey(f.Id) ? attachmentDict[f.Id] : null))
                            .ToList();
            return(CachedCiphers);
        }