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

            CapitalServiceClient client = new CapitalServiceClient();
            try
            {
                IsBusy = true;
                client.UpdateStatementCompleted += (s, e) =>
                {
                    if (e.Error == null)
                    {
                        // Check for tile and remove
                        string navParam = string.Format("Statement={0}", EditStatement.StatementId);
                        ShellTile TileToFind = ShellTile.ActiveTiles.Where(x => x.NavigationUri.ToString().Contains(navParam)).FirstOrDefault();
                        if (TileToFind != null)
                        {
                            if (EditStatement.IsPaid)
                                TileToFind.Delete();
                            else
                            {
                                // Update old tile
                                PinStatementFromCommand();
                            }
                        }
                        UpdateViews();
                    }
                    else if (e.Error is FaultException<CapitalError>)
                    {
                        ErrorMessages.FaultError(e.Error.Message);
                    }
                    else
                    {
                        ErrorMessages.UnexpectedError();
                    }

                    IsBusy = false;
                };
                client.UpdateStatementAsync(editStatement);
            }
            catch
            {
                client.Abort();
            }
            finally
            {
                client.CloseAsync();
            }
        }