public async Task <FolderResponseModel> Get(string id) { var userId = _userService.GetProperUserId(User).Value; var folder = await _folderRepository.GetByIdAsync(new Guid(id), userId); if (folder == null) { throw new NotFoundException(); } return(new FolderResponseModel(folder)); }
public async Task <bool> SyncAsync(string id) { if (!_authService.IsAuthenticated) { return(false); } SyncStarted(); var cipher = await _cipherApiRepository.GetByIdAsync(id).ConfigureAwait(false); if (!cipher.Succeeded) { SyncCompleted(false); if (cipher.StatusCode == System.Net.HttpStatusCode.Forbidden || cipher.StatusCode == System.Net.HttpStatusCode.Unauthorized) { MessagingCenter.Send(Application.Current, "Logout", (string)null); } return(false); } switch (cipher.Result.Type) { case Enums.CipherType.Folder: var folderData = new FolderData(cipher.Result, _authService.UserId); var existingLocalFolder = _folderRepository.GetByIdAsync(id); if (existingLocalFolder == null) { await _folderRepository.InsertAsync(folderData).ConfigureAwait(false); } else { await _folderRepository.UpdateAsync(folderData).ConfigureAwait(false); } break; case Enums.CipherType.Site: var siteData = new SiteData(cipher.Result, _authService.UserId); var existingLocalSite = _siteRepository.GetByIdAsync(id); if (existingLocalSite == null) { await _siteRepository.InsertAsync(siteData).ConfigureAwait(false); } else { await _siteRepository.UpdateAsync(siteData).ConfigureAwait(false); } break; default: SyncCompleted(false); return(false); } SyncCompleted(true); return(true); }
public async Task <Folder> GetByIdAsync(string id) { var data = await _folderRepository.GetByIdAsync(id); if (data == null || data.UserId != _authService.UserId) { return(null); } var folder = new Folder(data); return(folder); }
public async Task MoveManyAsync(IEnumerable <Guid> cipherIds, Guid?destinationFolderId, Guid movingUserId) { if (destinationFolderId.HasValue) { var folder = await _folderRepository.GetByIdAsync(destinationFolderId.Value); if (folder == null || folder.UserId != movingUserId) { throw new BadRequestException("Invalid folder."); } } await _cipherRepository.MoveAsync(cipherIds, destinationFolderId, movingUserId); // push await _pushService.PushSyncCiphersAsync(movingUserId); }