public ActionResult Edit(string id) { try { Page Page = new Page(); if (!string.IsNullOrWhiteSpace(id)) { Page = PageDAO.LoadByBsonId(id); } ViewBag.Page = Page; } catch (Exception e) { Logging.WriteLog("ChimeraWebsite.Areas.Admin.Controllers.PageController.Edit()" + e.Message); } return View(); }
public ActionResult Editor_Publish(string pageData) { Page Page = new Page(); try { Page = JsonConvert.DeserializeObject<Page>(pageData); Page.Published = true; if (PageDAO.Save(Page)) { ChimeraWebsite.Helpers.AppCache.UpdatePageInCache(Page); } } catch (Exception e) { Logging.WriteLog("ChimeraWebsite.Areas.Admin.Controllers.PageController.Editor_Publish()" + e.Message); } return RedirectToAction("ViewPageHistory", "Page", new { pageId = Page.PageId }); }
/// <summary> /// Load the requested page from the app cache /// </summary> /// <param name="friendlyURL"></param> /// <returns></returns> public static Page GetPageFromCache(string friendlyURL) { Page Page = new Page(); Dictionary<string, Page> CurrentPageDictionary = PageDictionary; if (!PageDictionary.ContainsKey(friendlyURL)) { Page = PageDAO.LoadByURL(friendlyURL); if (!string.IsNullOrWhiteSpace(Page.Id)) { CurrentPageDictionary.Add(Page.PageFriendlyURL, Page); PageDictionary = CurrentPageDictionary; } } else { Page = CurrentPageDictionary[friendlyURL]; } return Page; }
/// <summary> /// Update the page in the cache if it exists in there post publish /// </summary> /// <param name="page"></param> public static void UpdatePageInCache(Page page) { Dictionary<string, Page> CurrentPageDictionary = PageDictionary; if (PageDictionary.ContainsKey(page.PageFriendlyURL)) { CurrentPageDictionary[page.PageFriendlyURL] = page; PageDictionary = CurrentPageDictionary; } }
/// <summary> /// Will save a brand new page revision so we can maintain the old page structure for revision history. /// Method will generate a new MongoDB ObjectId and UTC datetime for the entity. /// </summary> /// <param name="page">page to save</param> /// <returns>bool</returns> public static bool Save(Page page) { bool SaveSuccessful = true; //Create a new object id so we can maintain the revision history of a page, the "PageId" attribute will remain the same. page.Id = ObjectId.GenerateNewId().ToString(); //Timestamp of when the page was saved. page.ModifiedDateUTC = DateTime.UtcNow; //if we are publishing a page then make sure all pages in DB that exist with same page id are set to not published. if (page.Published) { //set all records with same page id to false before saving new page. var UpdateQuery = Query<Page>.EQ(e => e.PageId, page.PageId); var UpdateSetStatement = Update<Page>.Set(e => e.Published, false); SaveSuccessful = Execute.Update<Page>(COLLECTION_NAME, UpdateQuery, UpdateSetStatement); } SaveSuccessful = Execute.Save<Page>(COLLECTION_NAME, page); //delete versions more than 10 MongoCollection<Page> Collection = Execute.GetCollection<Page>(COLLECTION_NAME); List<Page> PageList = (from e in Collection.AsQueryable<Page>() where e.PageId.Equals(page.PageId) orderby e.ModifiedDateUTC descending select e).Skip(10).ToList(); List<string> PageIdList = (List<string>) (from e in PageList select e.Id).ToList(); var DeleteQuery = Query<Page>.In(e => e.Id, PageIdList); return SaveSuccessful && Execute.Delete<Page>(COLLECTION_NAME, DeleteQuery); }
/// <summary> /// Default constructor. /// </summary> public PageModel() { InEditMode = false; Page = new Page(); }
public ActionResult Edit_Post(string id, string pageTitle, string pageFriendlyURL, string published) { Page Page = new Page(); bool SavedIt = false; try { if (!string.IsNullOrWhiteSpace(id)) { Page = PageDAO.LoadByBsonId(id); } else { Page.CreateDefaultNewPage(); } Page.PageTitle = pageTitle; Page.PageFriendlyURL = pageFriendlyURL; Page.Published = Boolean.Parse(published); Page PageFriendlyURLExists = PageDAO.LoadByURL(Page.PageFriendlyURL); //can only save if another page type does not have the same page friendly url if (PageFriendlyURLExists == null || PageFriendlyURLExists.PageId.Equals(Page.PageId)) { SavedIt = true; AddWebUserMessageToSession(Request, String.Format("Successfully saved/updated page."), SUCCESS_MESSAGE_TYPE); PageDAO.Save(Page); } else { AddWebUserMessageToSession(Request, String.Format("Unable to save page, there is already a page type published with the friendly URL \"{0}\"", Page.PageFriendlyURL), FAILED_MESSAGE_TYPE); } } catch (Exception e) { Logging.WriteLog("ChimeraWebsite.Areas.Admin.Controllers.PageController.Edit_Post()" + e.Message); } //if we were trying to add a new page and were unable to save it if (string.IsNullOrWhiteSpace(id) && !SavedIt) { return RedirectToAction("Dashboard", "Home"); } return RedirectToAction("ViewPageHistory", "Page", new { pageId = Page.PageId }); }