/// <summary> /// Adds new chapter to book /// </summary> /// <param name="chapter"></param> public void AddChapter(ChapterModel chapter) { var chapters = FindBook(chapter.BookId).Chapters.ToList(); var c = chapters.FirstOrDefault(ch => ch.Title == chapter.Title); if (c != null) _db.Chapters.FirstOrDefault(ch => ch.Title == chapter.Title).Text = HttpUtility.UrlDecode(Utils.GetTaggedText(chapter.Text)); if (c == null) _db.Chapters.Add(new Chapter { Book = FindBook(chapter.BookId), Text = HttpUtility.UrlDecode(chapter.Text), Title = chapter.Title, Position = chapters.Count }); _db.SaveChanges(); }
public ActionResult CreateChapter(ChapterModel model) { _repository.AddChapter(model); var chId = _repository.FindBook(model.BookId).Chapters.FirstOrDefault(c => c.Title == model.Title).Id; return RedirectToAction("Show", new { bookId = model.BookId}); }