예제 #1
0
        private void CreateAccount()
        {
            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;

                EditAccount.UserId = GetUser().UserId;

                client.CreateAccountCompleted += (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.CreateAccountAsync(EditAccount);
            }
            catch (Exception)
            {
                client.Abort();
            }
            finally
            {
                client.CloseAsync();
            }
        }