public async Task <bool> deleteGoogleAccount(ThirdPartyAuthenticationForView modelData) { bool RetValue = false; ThirdPartyCalendarAuthenticationModel ThirdPartyAuth = db.ThirdPartyAuthentication.Where(obj => obj.ID == modelData.ID).Single(); if (ThirdPartyAuth != null) { UserCredential googleCredential = ThirdPartyAuth.getGoogleOauthCredentials(); try { await googleCredential.RefreshTokenAsync(CancellationToken.None).ConfigureAwait(false); await googleCredential.RevokeTokenAsync(CancellationToken.None).ConfigureAwait(false); db.ThirdPartyAuthentication.Remove(ThirdPartyAuth); RetValue = true; } catch (Exception e) { if (e.Message.Contains("invalid_grant")) { db.ThirdPartyAuthentication.Remove(ThirdPartyAuth); } else { throw e; } } //await ThirdPartyAuth.getGoogleOauthCredentials().RevokeTokenAsync(CancellationToken.None).ConfigureAwait(false); await db.SaveChangesAsync().ConfigureAwait(false); } return(RetValue); }
public async Task <ActionResult> deleteGoogleAccount(ThirdPartyAuthenticationForView modelData) { ThirdPartyCalendarAuthenticationModelsController thirdPartyController = new ThirdPartyCalendarAuthenticationModelsController(); await thirdPartyController.deleteGoogleAccount(modelData).ConfigureAwait(false); return(RedirectToAction("ImportCalendar")); }