public ActionResult Delete(int?ID, FormCollection collection) { var page = db.CMSPages.FirstOrDefault(x => x.ID == ID); if (page == null) { return(RedirectToAction("Index")); } deleteRecursive(page); db.SubmitChanges(); CMSPage.ClearAllCache(); return(RedirectToAction("Index")); }
public ActionResult Delete(int?ID, FormCollection collection) { var page = db.CMSPages.FirstOrDefault(x => x.ID == ID); if (page == null) { return(PartialView(null)); } deleteRecursive(page); db.SubmitChanges(); CMSPage.ClearAllCache(); var main = db.CMSPages.FirstOrDefault(x => !x.ParentID.HasValue) ?? (db.CMSPages.FirstOrDefault() ?? new CMSPage() { LastMod = DateTime.Now, }); return(new ContentResult() { Content = "<script type='text/javascript'>resetSelectNode('" + "#x" + main.ID + "');</script>" }); }
public ActionResult Recicle(FormCollection collection) { if (!collection["Restore"].IsNullOrEmpty()) { foreach (string key in collection.Keys) { if (key.StartsWith("p")) { var p = db.StoreProducts.FirstOrDefault(x => x.ID == key.Substring(1).ToInt()); if (p != null) { p.Deleted = false; db.SubmitChanges(); CatalogBrowser.Init().ClearAllCaches(); } } if (key.StartsWith("c")) { var c = db.StoreCategories.FirstOrDefault(x => x.ID == key.Substring(1).ToInt()); if (c != null) { RestoreCats(c); db.SubmitChanges(); CatalogBrowser.Init().ClearAllCaches(); } } if (key.StartsWith("x")) { var page = db.CMSPages.FirstOrDefault(x => x.ID == key.Substring(1).ToInt()); if (page != null) { RestorePages(page); db.SubmitChanges(); CMSPage.ClearAllCache(); } } } } else if (!collection["Delete"].IsNullOrEmpty()) { foreach (string key in collection.Keys) { if (key.StartsWith("p")) { var p = db.StoreProducts.FirstOrDefault(x => x.ID == key.Substring(1).ToInt()); if (p != null) { DeleteProductData(p); db.StoreProducts.DeleteOnSubmit(p); db.SubmitChanges(); CatalogBrowser.Init().ClearAllCaches(); } } if (key.StartsWith("c")) { var c = db.StoreCategories.FirstOrDefault(x => x.ID == key.Substring(1).ToInt()); if (c != null) { DeleteCategory(c); CatalogBrowser.Init().ClearAllCaches(); } } if (key.StartsWith("x")) { var page = db.CMSPages.FirstOrDefault(x => x.ID == key.Substring(1).ToInt()); if (page != null) { DeletePage(page); CMSPage.ClearAllCache(); } } } } else if (!collection["Clear"].IsNullOrEmpty()) { var recicle = db.CMSPages.Where(x => x.Deleted).ToList().Select(x => x.LoadLangValues()).Select(x => new RecicleItem() { Name = x.PageName, Code = "x" + x.ID }).ToList(); recicle.AddRange(db.StoreCategories.Where(x => x.Deleted) .Select(x => new RecicleItem() { Name = x.Name, Code = "c" + x.ID })); recicle.AddRange(db.StoreProducts.Where(x => x.Deleted).Select(x => new RecicleItem() { Name = x.Name, Code = "p" + x.ID })); foreach (var item in recicle) { if (item.Code.StartsWith("p")) { var p = db.StoreProducts.FirstOrDefault(x => x.ID == item.Code.Substring(1).ToInt()); if (p != null) { DeleteProductData(p); db.StoreProducts.DeleteOnSubmit(p); db.SubmitChanges(); CatalogBrowser.Init().ClearAllCaches(); } } if (item.Code.StartsWith("c")) { var c = db.StoreCategories.FirstOrDefault(x => x.ID == item.Code.Substring(1).ToInt()); if (c != null) { DeleteCategory(c); CatalogBrowser.Init().ClearAllCaches(); } } if (item.Code.StartsWith("x")) { var page = db.CMSPages.FirstOrDefault(x => x.ID == item.Code.Substring(1).ToInt()); if (page != null) { DeletePage(page); CMSPage.ClearAllCache(); } } } } return(Recicle()); }