public ActionResult Create(Chapter chapter) { if (ModelState.IsValid) { db.Chapters.Add(chapter); db.SaveChanges(); return RedirectToAction("Index"); } return View(chapter); }
private static List<Chapter> extractTOC(HtmlNode root, HtmlNode toc, Book book, Chapter parent = null) { HtmlNodeCollection nodes = toc.ChildNodes; List<Chapter> chapters = new List<Chapter>(); for (int i = 0; i < nodes.Count; i++) { HtmlNode li = nodes[i]; Chapter ch = new Chapter(); //ch.InBook = book; ch.Parent = parent; // source (epub) chapter's attribute string source = li.ChildNodes[0].Attributes["href"].Value; source = source.Substring(1, source.Length - 1); // calculate chapter id HtmlNode nearestSentence = getNextSentence(root, source); string newId = "ch-" + book.Id + "-" + nearestSentence.Id; ch.ChapterId = newId; ch.Order = getOrder(nearestSentence.Id); //refresh hrefs in contents and ids of chapter anchors nodes[i].FirstChild.Attributes["href"].Value = "#" + newId; nodes[i].FirstChild.SetAttributeValue("class", "chapter"); root.SelectSingleNode( "//body//*[@id='" + source + "']").Id = newId; if (li.ChildNodes.Count > 1) { List<Chapter> child_li = extractTOC(root, li.ChildNodes[1], book, ch); ch.Children = child_li; } chapters.Add(ch); } return chapters; }
public ActionResult Edit(Chapter chapter) { if (ModelState.IsValid) { db.Entry(chapter).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(chapter); }