ClientUI.ViewModel.ObservableConnection.SaveCommand C# (CSharp) Method

SaveCommand() private method

private SaveCommand ( ) : void
return void
        public void SaveCommand()
        {
            if (!((IValidatedObservable)this).IsValid())
            {
                ((IValidatedObservable)(object)this).Errors.ShowAllMessages(true);
                return;
            }

            this.IsBusy.SetValue(true);
            this.AddNewVisible.SetValue(false);

            Connection connection = new Connection();
            connection.Record1Id = Record1Id.GetValue();
            connection.Record2Id = Record2Id.GetValue();
            connection.Record1RoleId = Record1RoleId.GetValue();
            connection.Record2RoleId = Record2RoleId.GetValue();

            EntityReference oppositeRole = GetOppositeRole(connection.Record1RoleId,  connection.Record2Id);
            connection.Record2RoleId = oppositeRole;

            OrganizationServiceProxy.BeginCreate(connection, delegate(object state)
            {
                try
                {
                    ConnectionId.SetValue(OrganizationServiceProxy.EndCreate(state));
                    OnSaveComplete(null);
                    Record1Id.SetValue(null);
                    Record1RoleId.SetValue(null);
                    ((IValidatedObservable)(object)this).Errors.ShowAllMessages(false);

                }
                catch (Exception ex)
                {
                    // Something went wrong - report it
                    OnSaveComplete(ex.Message);
                }
                finally
                {
                    this.IsBusy.SetValue(false);
                }

            });
        }

Usage Example

示例#1
0
 public static void CreateConnection(Assert assert)
 {
     assert.Expect(1);
     Action done = assert.Async();
     ObservableConnection vm = new ObservableConnection();
     vm.Record1Id.SetValue(accounts[0].ToEntityReference());
     vm.Record2Id.SetValue(accounts[1].ToEntityReference());
     vm.OnSaveComplete += delegate(string result)
     {
         assert.Equal(result, "Error", "Message = " + result);
         done();
     };
     vm.SaveCommand();
 }