public ActionResult setpageasdefault(int id, int oldid) { var pageoriginal = (from p in db.pages where p.pageID == oldid select p).First(); var pagecached = (from p in db.pages where p.pageID == id select p).First(); var temppage = new Models.page(); temppage.lastUpdate = pageoriginal.lastUpdate; temppage.pageContent = pageoriginal.pageContent; temppage.pageTitle = pageoriginal.pageTitle; temppage.pageURL = pageoriginal.pageURL; temppage.author = pageoriginal.author; pageoriginal.lastUpdate = DateTime.Now; pageoriginal.pageContent = pagecached.pageContent; pageoriginal.pageTitle = pagecached.pageTitle; pageoriginal.pageURL = pagecached.pageURL; pageoriginal.author = pagecached.author; pagecached.lastUpdate = temppage.lastUpdate; pagecached.pageContent = temppage.pageContent; pagecached.pageTitle = temppage.pageTitle; pagecached.pageURL = temppage.pageURL; pagecached.author = temppage.author; db.SubmitChanges(); return RedirectToAction("EditTemplate", new { id = oldid }); }
public ActionResult EditTemplate(int id, Models.AdminPageModel pagetoedit) { var pageoriginal = (from p in db.pages where p.pageID == id select p).First(); Admin admin = new Admin(); ViewData["parentPages"] = admin.getParentPages((int)pageoriginal.parent); if (string.IsNullOrEmpty(pagetoedit.page.pageContent)) { ModelState.AddModelError("page_text", "Text cannot be empty"); } if (string.IsNullOrEmpty(pagetoedit.page.pageTitle)) { ModelState.AddModelError("page_title", "Title cannot be empty"); } if (pageoriginal.pageTitle.Length < pageoriginal.pageTitle.Length) { ModelState.AddModelError("press_link", "Your link cannot be longer than " + pageoriginal.pageTitle.Length + " characters. Currently it is " + pagetoedit.page.pageTitle.Length); } if (!ModelState.IsValid) { return View(pagetoedit); } var parentPage = db.pages.Single(d => d.pageID == (int)pagetoedit.parentPageID); string pageURL = parentPage.pageURL + createPageURL(pagetoedit.page.pageTitle) + "/"; var cachedPages = from p in db.pages where p.pageURL == pageoriginal.pageURL && p.isPublished == false orderby p.lastUpdate descending select p; foreach (var cachedPage in cachedPages) { cachedPage.pageURL = pageURL; } var user = Membership.GetUser(); var pagetocache = new Models.page(); pagetocache.lastUpdate = pageoriginal.lastUpdate; pagetocache.pageContent = pageoriginal.pageContent; pagetocache.pageTitle = pageoriginal.pageTitle; pagetocache.pageURL = pageURL; pagetocache.isPublished = false; pagetocache.pageOrder = pageoriginal.pageOrder; pagetocache.parent = (int)pagetoedit.parentPageID; pagetocache.author = pageoriginal.author; db.pages.InsertOnSubmit(pagetocache); pageoriginal.pageTitle = pagetoedit.page.pageTitle; pageoriginal.pageContent = pagetoedit.page.pageContent; pageoriginal.pageURL = pageURL; pageoriginal.isPublished = (bool)pagetoedit.isPublished; pageoriginal.parent = (int)pagetoedit.parentPageID; pageoriginal.pageOrder = pagetoedit.page.pageOrder; pageoriginal.lastUpdate = DateTime.Now; pageoriginal.author = (Guid) user.ProviderUserKey; db.SubmitChanges(); return RedirectToAction("Index"); }