コード例 #1
0
        private async void DeleteAccount(object param)
        {
            var userAccount = param as UserAccount;

            if (userAccount == null)
            {
                return;
            }

            var userAccountViewModel = SelectedUserAccountViewModels.FirstOrDefault(a => a.UserAccount.AccountName.Equals(userAccount.AccountName));

            if (userAccountViewModel != null)
            {
                Close(userAccountViewModel);
            }

            try
            {
                await accountsService.DeleteAccount(userAccount);

                Accounts.Remove(userAccount);
                Module.RemoveAccount(userAccount.AccountName);
            }
            catch (Exception ex)
            {
                ShowMessage(new Message {
                    MessageType = MessageType.Error, Text = ex.Message
                });
            }
        }
コード例 #2
0
        private async void DeleteAccount(object param)
        {
            var userAccount = param as UserAccount;

            if (userAccount == null)
            {
                return;
            }

            var result = Dialog.ShowMessage(new MessageBoxSettings
            {
                Title             = "Delete User Account",
                Text              = $"Are you sure you want to delete {userAccount.AccountName}?",
                MessageType       = MessageType.Question,
                MessageBoxButtons = MessageBoxButtons.OkCancel
            });

            if (result.Equals(MessageBoxResult.Cancel))
            {
                return;
            }

            var userAccountViewModel = SelectedUserAccountViewModels.FirstOrDefault(a => a.UserAccount.AccountName.Equals(userAccount.AccountName));

            if (userAccountViewModel != null)
            {
                Close(userAccountViewModel);
            }

            try
            {
                IsLoading = true;

                await accountsService.DeleteAccountAsync(userAccount);

                Accounts.Remove(userAccount);
                Module.RemoveAccount(userAccount.AccountName);
            }
            catch (Exception ex)
            {
                ShowMessage(new Message {
                    MessageType = MessageType.Error, Text = ex.Message
                });
            }
            finally
            {
                IsLoading = false;
            }
        }