Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }