Example #1
0
        /// <summary>
        /// Deletes the given record or displays validation errors if cannot delete
        /// GET: /Admin/Article/Delete/5
        /// </summary>
        public ActionResult Delete(int id, string returnPage)
        {
            var record = Models.Article.LoadID(id);

            // first delete any child records that are OK to delete
            //ifsubform: record.example.DeleteAll();
            record.ArticleURLs.DeleteAll(false);
            record.ArticleDocuments.DeleteAll(false);
            // then prevent deletion if any other related records exist
            string issues = record.CheckForDependentRecords();

            if (issues.IsNotBlank())
            {
                Web.ErrorMessage = "Cannot delete this record. " + issues;
                return(RedirectToEdit(record.ID));
            }
            CheckLock(record);
            lockobj.UnLockTable(record.GetTableName(), record.ID);
            //ifsubform: record.example.Save();  // is this needed?
            // delete the keywords DeletePhrase(string tableName, int recordID) {
            AutocompletePhrase.DeletePhrase("Article", record.ID);
            // do the same for the document titles
            foreach (var document in record.ArticleDocuments)
            {
                AutocompletePhrase.DeletePhrase("ArticleDocument", document.ID);
            }
            // do the same for the url titles
            foreach (var url in record.ArticleURLs)
            {
                AutocompletePhrase.DeletePhrase("ArticleURL", url.ID);
            }
            record.ArticleURLs.Save();
            record.ArticleDocuments.Save();
            record.Delete();
            ArticleCache.Rebuild();
            Web.InfoMessage = "Record deleted.";
            return(Redirect(returnPage));
        }