예제 #1
0
        private void SaveAccount()
        {
            object focusObj = FocusManager.GetFocusedElement();
            if (focusObj != null && focusObj is TextBox)
            {
                var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty);
                binding.UpdateSource();
                (focusObj as TextBox).IsEnabled = false;
                (focusObj as TextBox).IsEnabled = true;
                return;
            }

            if (!Validate())
                return;

            CapitalServiceClient client = new CapitalServiceClient();

            try
            {
                IsBusy = true;

                client.UpdateAccountCompleted += (s, e) =>
                {
                    if (e.Error == null)
                    {
                        UpdateViews();
                    }
                    else if (e.Error is FaultException<CapitalError>)
                    {
                        ErrorMessages.FaultError(e.Error.Message);
                    }
                    else
                    {
                        ErrorMessages.UnexpectedError();
                    }
                    IsBusy = false;
                };
                client.UpdateAccountAsync(EditAccount);
            }
            catch
            {
                client.Abort();
            }
            finally
            {
                client.CloseAsync();
            }
        }