public ActionResult Create(Page page, string html) { try { TempData["html"] = html; // Save our html incase there is an error service.Save(page, html); // Save our html return RedirectToAction("Index"); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message.ToString()); return View(page); } }
public ActionResult Edit(Page page) { try { // TODO: Add update logic here return RedirectToAction("Index"); } catch { return View(); } }
public IList<Page> GetAll() { var fullPath = HttpContext.Current.Server.MapPath(project.Location + pagePath); var pages = new List<Page>(); foreach (var file in Directory.GetFiles(fullPath)) { using (var sr = new StreamReader(file)) { var line = sr.ReadToEnd(); var json = JObject.Parse(line); var page = new Page() { Id = json["id"].ToString(), ParentId = (json["parent"] == null) ? null : json["parent"].ToString(), Title = (json["title"] == null) ? json["id"].ToString() : json["title"].ToString(), Path = file, ProjectId = project.Id }; pages.Add(page); } } return pages; }
private string ParseHtml(Page page, string html) { var doc = new HtmlDocument(); var sb = new StringBuilder(); var additionalJson = ""; if (!string.IsNullOrEmpty(page.ParentId)) additionalJson += ",\"parent\":\"" + page.ParentId + "\""; doc.LoadHtml(html); CreateJson(sb, ParseNode(doc.DocumentNode.FirstChild, additionalJson)); // Get the first node return sb.ToString(); }
private void CreateItem(int level, StringBuilder sb, Page page) { sb.Append("<li id=\"order-" + page.Order + "\"><span class=\"tick\"></span><span class=\"actions\"><div class=\"btn-group\"><a class=\"view-page btn btn-default btn-small\" href=\"#\" data-id=\"" + page.Id + "\">View</a><a class=\"edit-page btn btn-default btn-small\" href=\"/Pages/Edit?id=" + page.Id + "\">Edit</a><a class=\"delete-page btn btn-default btn-small\" href=\"#\" data-id=\"" + page.Id + "\">Delete</a></div></span><div class=\"item\" id=\"" + page.Id + "\" title=\"" + page.Title + "\"><span class=\"arr indent" + level + "\"></span><span class=\"title\">" + page.Title + "</span></div>"); sb.Append(BuildChildren(page.Id, level + 1)); sb.Append("</li>"); }
public void Save(Page page, string encodedHtml) { var target = HttpContext.Current.Server.MapPath(Path.Combine(project.Location + pagePath, page.Id + ".txt")); if (string.IsNullOrEmpty(encodedHtml)) throw new ArgumentNullException("encodedHtml"); if (File.Exists(target)) throw new IOException("This page already exists"); var decodedHtml = System.Uri.UnescapeDataString(encodedHtml).Trim().Replace(System.Environment.NewLine, ""); var json = JsonConvert.SerializeObject(JObject.Parse(ParseHtml(page, decodedHtml)), Formatting.Indented); File.WriteAllText(target, json); }