public ActionResult DisableAutoTagging(string id)
        {
            LogHelper.Log("Entering DisableAutoTagging");
            try
            {
                var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
                AppWebHelper hlp = new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
                using (var ctx = spContext.CreateUserClientContextForSPHost())
                {
                    string[] ids = id.Split(new char[] { '_' });
                    LogHelper.Log("Inside DisableAutoTagging");
                    if (hlp.DisableTaggingOnListField(ids[1],ids[0]) == 0) //Only delete the RER if no more fields are enabled.
                    {
                        
                        List TargetList = ctx.Web.Lists.GetById(new Guid(ids[0]));
                        ctx.Load(TargetList.EventReceivers);
                        ctx.Load(TargetList);
                        ctx.ExecuteQuery();
                        LogHelper.Log("Before EnableDisableTagging");
                        ConfigurationHelper.EnableDisableTagging(ctx, TargetList, false,hlp);
                        LogHelper.Log("After EnableDisableTagging");
                    }

                    return PartialView("ListFields", GetModel(ctx, new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string)));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
                throw;
            }
            
        }
        public void HandleAutoTaggingFieldDeleted(SPRemoteEventProperties properties)
        {
            
            string TargetFieldId = GetFieldId(properties.ListEventProperties.FieldXml);
            LogHelper.Log("Field "+TargetFieldId+" was deleted, cleaning config list");
            Uri webUri = new Uri(properties.ListEventProperties.WebUrl);
            string realm = TokenHelper.GetRealmFromTargetUrl(webUri);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(
                TokenHelper.SharePointPrincipal, webUri.Authority, realm).AccessToken;
            using (var ctx = TokenHelper.GetClientContextWithAccessToken(properties.ListEventProperties.WebUrl, accessToken))
            {
                if (ctx != null)
                {
                    ctx.Load(ctx.Web.AllProperties);
                    ctx.ExecuteQuery();
                    AppWebHelper hlp = new AppWebHelper(properties.ListEventProperties.WebUrl,false);
                    if (hlp.DisableTaggingOnListField(TargetFieldId, properties.ListEventProperties.ListId.ToString()) == 0) //Only delete the RER if no more fields are enabled.
                    {
                        

                
                                List TargetList = ctx.Web.Lists.GetById(properties.ListEventProperties.ListId);
                                ctx.Load(TargetList.EventReceivers);
                                ctx.Load(TargetList);
                                ctx.ExecuteQuery();
                                LogHelper.Log("Before EnableDisableTagging");
                                ConfigurationHelper.EnableDisableTagging(ctx, TargetList, false,hlp);
                                LogHelper.Log("After EnableDisableTagging");
                    }
                }                
            }
        }