Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        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() });
        }