public static void Publish(Page page) { string oldFileId = page.FileId; Delete(oldFileId); string newFileId = page.Title.Replace(" ", ""); page.FileId = CreateUniqueId(newFileId); page.Published = true; Save(page); }
public List<Page> GetPages() { string folder = Path; // get all pages List<Page> pages = new List<Page>(); foreach (string filePath in Directory.GetFiles(folder)) { XDocument doc = XDocument.Load(filePath); Page page = new Page(); page.Title = (string)doc.Root.Attribute("Title"); page.FileId = (string)doc.Root.Attribute("FileId"); page.Body = HttpContext.Current.Server.HtmlDecode(doc.Root.Value); pages.Add(page); } return pages; }
public ActionResult Compose(string id) { string fileId = id; Page page = new Page(); if (!string.IsNullOrEmpty(fileId)) { page = PageComp.Load(fileId); } var model = new ComposePageModel { FileId = page.FileId, Title = page.Title, Contents = page.Body }; return View(model); }
public ActionResult Publish(ComposePageModel pageModel) { // return if invalid model if (!ModelState.IsValid) return View(pageModel); Page page = new Page { FileId = pageModel.FileId, Title = pageModel.Title, Body = pageModel.Contents }; // Save the new page PageComp.Publish(page); TempData["Message"] = "页面已发布"; return this.RedirectToAction("Manage"); }
public ActionResult Close(Page page) { return this.RedirectToAction("Manage"); }
public ActionResult Save(ComposePageModel pageModel) { Page page = new Page { FileId = pageModel.FileId, Title = pageModel.Title, Body = pageModel.Contents }; // Ajax call, return Json message if (string.IsNullOrEmpty(page.FileId)) { // unique stuff. page.FileId = Guid.NewGuid().ToString(); } page.Body = page.Body ?? string.Empty; PageComp.Save(page); DateTime now = LocalTime.GetCurrentTime(TimeZoneInfo.FindSystemTimeZoneById(SettingsComp.GetSettings().Timezone)); StringWriter sw = new StringWriter(); IView view = new RazorView(this.ControllerContext, "~/Views/Shared/AutoSaveControl.cshtml", null, false, null); this.ViewData.Model = now; ViewContext viewContext = new ViewContext(this.ControllerContext, view, this.ViewData, this.TempData, sw); view.Render(viewContext, sw); // PartialViewResult result = RenderViewToString this.PartialView("AutoSaveControl", now); return Json(new SavePageResultModel { FileId = page.FileId, Content = sw.ToString() }); }
public Page Load(string fileId) { string filePath = GetPath(fileId); Page page = new Page(); page.FileId = fileId; XDocument doc = XDocument.Load(string.Format(filePath, fileId)); XElement elem = doc.Root; page.Title = (string)elem.Attribute("Title"); page.Body = HttpContext.Current.Server.HtmlDecode(elem.Value); return page; }
public void Save(Page page) { XDocument doc = XDocument.Parse("<Page></Page>"); doc.Root.SetAttributeValue("FileId", page.FileId); doc.Root.SetAttributeValue("Title", page.Title); doc.Root.SetValue(HttpContext.Current.Server.HtmlEncode(page.Body)); doc.Root.SetAttributeValue("Published", page.Published); doc.Save(GetPath(page.FileId)); }
public static void Save(Page page) { ConfigHelper.DataContext.PageData.Save(page); }