Exemplo n.º 1
0
        public async Task <bool> DeleteUserAccount(AccountUser user)
        {
            var result = new Result();

            try
            {
                result.IsSuccess = await AccountAuthHelpers.DeleteUserAccount(user);
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Error     = "Failed to delete user";
            }
            var resultCheck = await ResultChecker.CheckSuccess(result);

            if (resultCheck)
            {
                AccountUsers.Remove(user);
                if (Shell.Instance.ViewModel.CurrentUser != null && Shell.Instance.ViewModel.CurrentUser.Username == user.Username)
                {
                    Shell.Instance.ViewModel.CurrentUser = null;
                    Shell.Instance.ViewModel.IsLoggedIn  = false;
                    try
                    {
                        var pages = App.Frame.BackStack;
                        foreach (var page in pages)
                        {
                            App.Frame.BackStack.Remove(page);
                        }
                    }
                    catch (Exception)
                    {
                        // Failed to delete backstack :\
                    }
                }
                if (!AccountUsers.Any())
                {
                    NavigationService.Navigate(typeof(LoginPage));
                }
            }
            return(resultCheck);
        }
        public async Task <bool> DeleteUserAccount(AccountUser user)
        {
            Locator.ViewModels.MainPageVm.MenuItems = new List <MenuItem>();
            try
            {
                var pages = App.RootFrame.BackStack;
                foreach (var page in pages)
                {
                    App.RootFrame.BackStack.Remove(page);
                }
            }
            catch (Exception)
            {
                // Failed to delete backstack :\
            }
            var result = new Result();

            try
            {
                result.IsSuccess = await AccountAuthHelpers.DeleteUserAccount(user);
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Error     = "Failed to delete user";
            }
            var resultCheck = await ResultChecker.CheckSuccess(result);

            if (resultCheck)
            {
                AccountUsers.Remove(user);
                if (AccountUsers.Any())
                {
                    OnPropertyChanged("AccountUsers");
                    return(true);
                }
                App.RootFrame.Navigate(typeof(LoginPage));
            }
            return(resultCheck);
        }