public override ChapterVersion GetPreviousChapter(string chapterId, string articleId)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ChapterVersionDataStore chapVersion = new ChapterVersionDataStore(transaction);

                IList <ChapterVersion> chVersList = chapVersion.FindAllItemsByArticleId(articleId);

                int seq = 0;

                if (!string.IsNullOrEmpty(chapterId))  // if this is null then the first chapter is loaded by default.
                {
                    seq = chVersList.IndexOf(chVersList.First(x => x.Id.Equals(chapterId)));
                }

                if (seq == 0)
                {
                    return(new ChapterVersion());
                }
                else
                {
                    if (seq != 0)
                    {
                        return(chVersList.ElementAt(seq - 1));
                    }
                    else
                    {
                        return(new ChapterVersion());
                    }
                }
            }
        }
        public override void DeleteChapter(string chapterId)
        {
            try
            {
                using (TransactionScope transaction = new TransactionScope(mConfiguration))
                {
                    ChapterDataStore dataStore = new ChapterDataStore(transaction);
                    dataStore.Delete(chapterId);

                    ChapterVersionDataStore dsChapVersion  = new ChapterVersionDataStore(transaction);
                    IList <ChapterVersion>  chVersionsList = dsChapVersion.FindAllItems(chapterId);

                    foreach (ChapterVersion item in chVersionsList)
                    {
                        item.Deleted = true;
                        dsChapVersion.Update(item);
                    }

                    transaction.Commit();
                }
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        public override ChapterVersion CreateChapterVersion(string docId, ChapterVersion chapterVersion, VersionUpdateType versionUpdateType)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ChapterVersionDataStore dataStore = new ChapterVersionDataStore(transaction);


                int maxSequenceNumber = 0;

                if (versionUpdateType == VersionUpdateType.New)
                {
                    maxSequenceNumber = GetNewSequenceNo(docId); //only generate sequence number when adding a new chapter else use existing sequence number
                }
                else
                {
                    maxSequenceNumber = chapterVersion.Sequence;
                }

                chapterVersion.Version      = GenerateVersionNumber(versionUpdateType, chapterVersion.Version);
                chapterVersion.VersionOrder = GetVersionOrder(docId, chapterVersion.ChapterId);

                //if (!CheckChapterName(docId, chapterVersion.Name))
                // {
                ChapterVersion chapterVer = new ChapterVersion(docId, chapterVersion.ChapterId, chapterVersion.Name, chapterVersion.Content, chapterVersion.Version, chapterVersion.VersionOrder, maxSequenceNumber);

                dataStore.Insert(chapterVer);
                transaction.Commit();

                return(chapterVer);
                //}
                //else
                //  return chapterVersion;
            }
        }
 public override int GetLowestSequenceNumber(string articleId)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         ChapterVersionDataStore chapVersion = new ChapterVersionDataStore(transaction);
         return(chapVersion.LowestSeqNumber(articleId));
     }
 }
        public override IList <ChapterVersion> GetAllChapVersions()
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ChapterVersionDataStore chapVersion = new ChapterVersionDataStore(transaction);

                return(chapVersion.FindAllItems());
            }
        }
        public override ChapterVersion GetChapterVersion(string chapterId)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ChapterVersionDataStore chapVersion = new ChapterVersionDataStore(transaction);

                return(chapVersion.FindAllItems().First(x => x.Id.Equals(chapterId)));
            }
        }
        public override IList <ChapterVersion> GetAllItemsByArticleId(string articleId)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ChapterVersionDataStore chapVersion = new ChapterVersionDataStore(transaction);

                IList <ChapterVersion> dsChapters = chapVersion.FindAllItemsByArticleId(articleId);

                return(dsChapters);
            }
        }
        public override void UpdateChapterVersion(ChapterVersion chapterVers)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ChapterVersionDataStore dataStore = new ChapterVersionDataStore(transaction);

                dataStore.Update(chapterVers);

                transaction.Commit();
            }
        }
        public override IList <string> GetSubChapters(string chapterId)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ChapterVersionDataStore chapVersion = new ChapterVersionDataStore(transaction);

                ChapterVersion cv        = chapVersion.FindAllItems().First(x => x.Id.Equals(chapterId));
                XHTMLText      xhtmlText = new XHTMLText();

                IList <string> subChapters = xhtmlText.GetSubChapters(cv.Content);

                return(subChapters);
            }
        }
        public override IList <SubSectionChap> GetChapterSubSection(string chapterId)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ChapterVersionDataStore chapVersion = new ChapterVersionDataStore(transaction);

                ChapterVersion cv        = chapVersion.FindAllItems().First(x => x.Id.Equals(chapterId));
                XHTMLText      xhtmlText = new XHTMLText();

                IList <string> subChapters = xhtmlText.GetSubChapters(cv.Content);

                List <SubSectionChap> chapSections = new List <SubSectionChap>();
                foreach (string subSec in subChapters)
                {
                    chapSections.Add(new SubSectionChap {
                        ChapId = chapterId, AnchorTag = subSec
                    });
                }
                return(chapSections);
            }
        }