Пример #1
0
        public async Task Delete(string id)
        {
            var userId = _userService.GetProperUserId(User).Value;
            var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId);

            if (cipher == null)
            {
                throw new NotFoundException();
            }

            await _cipherService.DeleteAsync(cipher, userId);
        }
Пример #2
0
        private async void DeleteCell_Tapped(object sender, EventArgs e)
        {
            if (!_connectivity.IsConnected)
            {
                AlertNoConnection();
                return;
            }

            if (!await _userDialogs.ConfirmAsync(AppResources.DoYouReallyWantToDelete, null, AppResources.Yes, AppResources.No))
            {
                return;
            }

            _userDialogs.ShowLoading(AppResources.Deleting, MaskType.Black);
            var deleteTask = await _cipherService.DeleteAsync(_cipherId);

            _userDialogs.HideLoading();

            if (deleteTask.Succeeded)
            {
                _userDialogs.Toast(AppResources.ItemDeleted);
                _googleAnalyticsService.TrackAppEvent("DeletedCipher");
                await Navigation.PopForDeviceAsync();
            }
            else if (deleteTask.Errors.Count() > 0)
            {
                await _userDialogs.AlertAsync(deleteTask.Errors.First().Message, AppResources.AnErrorHasOccurred);
            }
            else
            {
                await _userDialogs.AlertAsync(AppResources.AnErrorHasOccurred);
            }
        }
Пример #3
0
        public async Task Delete(string id)
        {
            var login = await _cipherRepository.GetByIdAsync(new Guid(id), _userService.GetProperUserId(User).Value);

            if (login == null || login.Type != Core.Enums.CipherType.Login)
            {
                throw new NotFoundException();
            }

            await _cipherService.DeleteAsync(login);
        }
Пример #4
0
        public async Task Delete(string id)
        {
            var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), new Guid(_userManager.GetUserId(User)));

            if (cipher == null)
            {
                throw new NotFoundException();
            }

            await _cipherService.DeleteAsync(cipher);
        }
Пример #5
0
        public async Task Delete(string id)
        {
            var site = await _cipherRepository.GetByIdAsync(new Guid(id), new Guid(_userManager.GetUserId(User)));

            if (site == null || site.Type != Core.Enums.CipherType.Site)
            {
                throw new NotFoundException();
            }

            await _cipherService.DeleteAsync(site);
        }
Пример #6
0
        private async void DeleteCell_Tapped(object sender, EventArgs e)
        {
            if (!_connectivity.IsConnected)
            {
                AlertNoConnection();
                return;
            }

            var confirmed = await DisplayAlert(null, AppResources.DoYouReallyWantToDelete, AppResources.Yes,
                                               AppResources.No);

            if (!confirmed)
            {
                return;
            }

            await _deviceActionService.ShowLoadingAsync(AppResources.Deleting);

            var deleteTask = await _cipherService.DeleteAsync(_cipherId);

            await _deviceActionService.HideLoadingAsync();

            if (deleteTask.Succeeded)
            {
                _deviceActionService.Toast(AppResources.ItemDeleted);
                _googleAnalyticsService.TrackAppEvent("DeletedCipher");
                await Navigation.PopForDeviceAsync();
            }
            else if (deleteTask.Errors.Count() > 0)
            {
                await DisplayAlert(AppResources.AnErrorHasOccurred, deleteTask.Errors.First().Message, AppResources.Ok);
            }
            else
            {
                await DisplayAlert(null, AppResources.AnErrorHasOccurred, AppResources.Ok);
            }
        }
Пример #7
0
        public async Task <bool> SyncUpsertCipherAsync(SyncCipherNotification notification, bool isEdit)
        {
            SyncStarted();
            if (await _stateService.IsAuthenticatedAsync())
            {
                try
                {
                    var shouldUpdate = true;
                    var localCipher  = await _cipherService.GetAsync(notification.Id);

                    if (localCipher != null && localCipher.RevisionDate >= notification.RevisionDate)
                    {
                        shouldUpdate = false;
                    }

                    var checkCollections = false;
                    if (shouldUpdate)
                    {
                        if (isEdit)
                        {
                            shouldUpdate     = localCipher != null;
                            checkCollections = true;
                        }
                        else
                        {
                            if (notification.CollectionIds == null || notification.OrganizationId == null)
                            {
                                shouldUpdate = localCipher == null;
                            }
                            else
                            {
                                shouldUpdate     = false;
                                checkCollections = true;
                            }
                        }
                    }

                    if (!shouldUpdate && checkCollections && notification.OrganizationId != null &&
                        notification.CollectionIds != null && notification.CollectionIds.Any())
                    {
                        var collections = await _collectionService.GetAllAsync();

                        if (collections != null)
                        {
                            foreach (var c in collections)
                            {
                                if (notification.CollectionIds.Contains(c.Id))
                                {
                                    shouldUpdate = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (shouldUpdate)
                    {
                        var remoteCipher = await _apiService.GetCipherAsync(notification.Id);

                        if (remoteCipher != null)
                        {
                            var userId = await _stateService.GetActiveUserIdAsync();

                            await _cipherService.UpsertAsync(new CipherData(remoteCipher, userId));

                            _messagingService.Send("syncedUpsertedCipher", new Dictionary <string, string>
                            {
                                ["cipherId"] = notification.Id
                            });
                            return(SyncCompleted(true));
                        }
                    }
                }
                catch (ApiException e)
                {
                    if (e.Error != null && e.Error.StatusCode == System.Net.HttpStatusCode.NotFound && isEdit)
                    {
                        await _cipherService.DeleteAsync(notification.Id);

                        _messagingService.Send("syncedDeletedCipher", new Dictionary <string, string>
                        {
                            ["cipherId"] = notification.Id
                        });
                        return(SyncCompleted(true));
                    }
                }
            }
            return(SyncCompleted(false));
        }