public async Task <ActionResult> Delete(string id = null, string listId = null) { using (var cc = ContextProvider.GetWebApplicationClientContext(Settings.SiteCollection)) { if (cc != null) { // Hookup event to capture access token cc.ExecutingWebRequest += Cc_ExecutingWebRequest; // Just load the Url property to trigger the ExecutingWebRequest event handler to fire cc.Load(cc.Web, w => w.Url); cc.ExecuteQueryRetry(); WebHookManager webHookManager = new WebHookManager(); // delete the web hook if (await webHookManager.DeleteListWebHookAsync(cc.Web.Url, listId, id, this.accessToken)) { using (SharePointWebHooks dbContext = new SharePointWebHooks()) { var webHookRow = await dbContext.ListWebHooks.FindAsync(new Guid(id)); if (webHookRow != null) { dbContext.ListWebHooks.Remove(webHookRow); var saveResult = await dbContext.SaveChangesAsync(); } } } } } return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> Delete(string id = null, string listId = null) { var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (var cc = spContext.CreateUserClientContextForSPHost()) { if (cc != null) { // Hookup event to capture access token cc.ExecutingWebRequest += Cc_ExecutingWebRequest; // Just load the Url property to trigger the ExecutingWebRequest event handler to fire cc.Load(cc.Web, w => w.Url); cc.ExecuteQueryRetry(); var webHookManager = new WebHookManager(); // delete the web hook if (await webHookManager.DeleteListWebHookAsync(cc.Web.Url, listId, id, this.accessToken)) { using (var dbContext = new SharePointWebHooks()) { var webHookRow = await dbContext.ListWebHooks.FindAsync(new Guid(id)); if (webHookRow != null) { dbContext.ListWebHooks.Remove(webHookRow); var saveResult = await dbContext.SaveChangesAsync(); } } } } } return(RedirectToAction($"Index", $"Home", new { SPHostUrl = Request.QueryString[$"SPHostUrl"] })); }