public async Task <Login> GetByIdAsync(string id) { var data = await _loginRepository.GetByIdAsync(id); if (data == null || data.UserId != _authService.UserId) { return(null); } var attachments = await _attachmentRepository.GetAllByLoginIdAsync(id); var login = new Login(data, attachments); return(login); }
public async Task <bool> SyncCipherAsync(string id) { if (!_authService.IsAuthenticated) { return(false); } SyncStarted(); var cipher = await _cipherApiRepository.GetByIdAsync(id).ConfigureAwait(false); if (!CheckSuccess(cipher)) { return(false); } try { switch (cipher.Result.Type) { case Enums.CipherType.Login: var loginData = new LoginData(cipher.Result, _authService.UserId); await _loginRepository.UpsertAsync(loginData).ConfigureAwait(false); var localAttachments = (await _attachmentRepository.GetAllByLoginIdAsync(loginData.Id) .ConfigureAwait(false)); if (cipher.Result.Attachments != null) { foreach (var attachment in cipher.Result.Attachments) { var attachmentData = new AttachmentData(attachment, loginData.Id); await _attachmentRepository.UpsertAsync(attachmentData).ConfigureAwait(false); } } if (localAttachments != null) { foreach (var attachment in localAttachments .Where(a => !cipher.Result.Attachments.Any(sa => sa.Id == a.Id))) { try { await _attachmentRepository.DeleteAsync(attachment.Id).ConfigureAwait(false); } catch (SQLite.SQLiteException) { } } } break; default: SyncCompleted(false); return(false); } } catch (SQLite.SQLiteException) { SyncCompleted(false); return(false); } SyncCompleted(true); return(true); }