public override Draft UpsertDraft(Draft draft)
        {
            try
            {
                using (TransactionScope transaction = new TransactionScope(mConfiguration))
                {
                    DraftDataStore dataStore = new DraftDataStore(transaction);

                    IList <Draft> listDrafts = dataStore.FindItemByChapterId(draft.VersionId);
                    if (listDrafts.Count > 0)
                    {
                        string tempContent = draft.Content;
                        draft         = listDrafts.First <Draft>();
                        draft.Content = tempContent;
                        dataStore.Update(draft);
                    }
                    else
                    {
                        dataStore.Insert(draft);
                    }

                    transaction.Commit();

                    return(draft);
                }
            }
            catch (NotImplementedException ex)
            {
                throw ex;
            }
        }
 public override IList <Draft> GetDraftsByChapterId(string chapterId)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         DraftDataStore dsDraft = new DraftDataStore(transaction);
         IList <Draft>  drafts  = dsDraft.FindItemByChapterId(chapterId);
         return(drafts);
     }
 }
        public override Draft GetDraftByChapterId(string chapterId)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                DraftDataStore dsDraft = new DraftDataStore(transaction);
                IList <Draft>  drafts  = dsDraft.FindItemByChapterId(chapterId);

                if (drafts.Count > 0)
                {
                    return(drafts.First <Draft>());
                }
                else
                {
                    return(null);
                }
            }
        }
        public override void DeleteDraft(string chapterVersionId, bool deleteAll, string draftId, string newChapterVersionId)
        {
            try
            {
                using (TransactionScope transaction = new TransactionScope(mConfiguration))
                {
                    DraftDataStore dataStore = new DraftDataStore(transaction);

                    //items are returned in sorted order - Sorted by SaveDate desc.
                    //delete only one record
                    if (!deleteAll)
                    {
                        if (!string.IsNullOrEmpty(draftId))
                        {
                            Draft draft = new Draft();
                            draft = dataStore.FindItemByDraftId(draftId).First(x => x.Id.Equals(draftId));

                            draft.Deleted = true;
                            dataStore.Update(draft);
                        }

                        //update previous drafts if any

                        IList <Draft> drafts = dataStore.FindItemByChapterId(chapterVersionId);
                        if (drafts.Count > 0)
                        {
                            foreach (Draft item in drafts)
                            {
                                item.VersionId = newChapterVersionId;
                                dataStore.Update(item);
                            }
                        }
                    }
                    //delete all previous records.
                    else
                    {
                        IList <Draft> drafts = dataStore.FindItemByChapterId(chapterVersionId);

                        if (drafts.Count > 0)
                        {
                            foreach (Draft item in drafts)
                            {
                                if (!string.IsNullOrEmpty(newChapterVersionId))
                                {
                                    if (item.Id != draftId)
                                    {
                                        item.Deleted = true;
                                        dataStore.Update(item);
                                    }
                                }
                                else
                                {
                                    item.Deleted = true;
                                    dataStore.Update(item);
                                }
                            }
                        }
                    }
                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }