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);
}
});
}