Example #1
0
        public int SaveChanges(ChapterForm form)
        {
            var tChapter = Table <Chapter>();

            var chapter = tChapter.GetOrAdd(w => w.ID == form.ID ||
                                            (w.ID == 0 && w.NovelID == form.NovelID && w.Volume == form.Volume && w.Number == form.Number));

            MapProperty(form, chapter, form.InlineEditProperty);
            UpdateAuditFields(chapter, form.ByUserID);
            // save
            SaveChanges();

            // save chapter content
            if (!string.IsNullOrWhiteSpace(form.Content))
            {
                var tContent = Table <Content>();

                var segments = form.Content.SegmentChapterContent();
                foreach (var segment in segments)
                {
                    var content = tContent.GetOrAdd(w => w.ChapterID == chapter.ID && w.RawHash == segment.Key);
                    if (content.ID == 0) // only add when the paragraph is new (does not exist)
                    {
                        UpdateAuditFields(content, form.ByUserID);
                        content.ChapterID = chapter.ID;
                        content.RawHash   = segment.Key;
                        content.Final     = segment.Value;

                        // save
                        SaveChanges();
                    }
                }
            }
            return(chapter.ID);
        }
Example #2
0
 public int AddChapter(ChapterForm chapterForm)
 {
     using (var uow = UnitOfWorkFactory.Create <NovelContext>())
     {
         var service = new ChapterService(uow);
         return(service.SaveChanges(chapterForm));
     }
 }
Example #3
0
 public ActionResult Add(ChapterForm form)
 {
     return(View(form));
 }
Example #4
0
 public JsonResult Form(ChapterForm chapter)
 {
     return(SaveChanges(chapter, Facade <NovelFacade>().AddChapter));
 }