async private void ButtonMembership_ClickedAsync(object sender, EventArgs e) { IsServiceActive = true; try { Invitation invitation = AppInviteList.SelectedItem as Invitation; if (invitation == null) { return; } AppViewModel appModel = BaseViewModels.AppCollectionViewModel.AppModels.Where( m => m.EditApp.Tag == invitation.AppTag).FirstOrDefault();; App joinApp; if (appModel != null) { joinApp = appModel.EditApp; } else { App searchApp = new App(); searchApp.Tag = invitation.AppTag; appModel = new AppViewModel(_contactsModel.Platform); ResultSingle <App> appResult = await appModel.QueryAppAsync( searchApp, false); if (appResult.Code != Cloud.ServerStatus.NEST_RESULT_SUCCESS) { await ErrorHandler.ExceptionAsync(this, "This app no longer exisit"); return; } joinApp = searchApp; } Contact myContact = new Contact(); invitation.CopyTo(myContact); joinApp.OwnedBy = BaseViewModels.Platform.Permit.Owner; myContact.OwnedBy = joinApp; ResultSingle <Contact> contactResult = await appModel .ContactViewModel.UpdateContactAsync(myContact); if (contactResult.Code != Cloud.ServerStatus.NEST_RESULT_SUCCESS) { await ErrorHandler.ExceptionAsync(this, "Could not confirm the invitation"); return; } contactResult.Data.Payload.CopyTo(invitation); AppCollectionViewModel appCollection = BaseViewModels.AppCollectionViewModel; if (invitation.Status == "active") { appCollection.AddApp(joinApp); } else { foreach (AppViewModel appRemoveeModel in appCollection.AppModels) { if (appRemoveeModel.EditApp.Id == joinApp.Id) { appCollection.RemoveApp(appRemoveeModel); break; } } } ToggleMembershipButton(invitation); } catch (Exception ex) { await ErrorHandler.ExceptionAsync(this, ex); } IsServiceActive = false; }