public ReaderService.Chapter ChaptertoSvcChapter(Models.Chapter b)
 {
     ReaderService.Chapter val = new ReaderService.Chapter();
     val.BookID            = b.BookID;
     val.ChapterAddress    = b.ChapterAddress;
     val.ChapterHtml       = b.ChapterHTML;
     val.ChapterID         = b.ChapterID;
     val.ChapterName       = b.ChapterName;
     val.ChapterText       = b.ChapterText;
     val.PreviousChapterID = b.PreviousChapterID;
     return(val);
 }
        public Models.Chapter GetLastChapter(int bookID)
        {
            //MasterController mc = new MasterController();
            Models.Chapter chap = new Models.Chapter();

            using (ReaderService.ReaderServiceSoapClient svc = new ReaderService.ReaderServiceSoapClient())
            {
                chap = this.SvcChaptertoChapter(svc.GetLastChapter(ProgramStatics.Token, bookID));
            }

            return(chap);
        }
        public Models.Chapter SvcChaptertoChapter(ReaderService.Chapter b)
        {
            Models.Chapter val = new Models.Chapter();
            val.BookID            = b.BookID;
            val.ChapterAddress    = b.ChapterAddress;
            val.ChapterHTML       = b.ChapterHtml;
            val.ChapterID         = b.ChapterID;
            val.ChapterName       = b.ChapterName;
            val.ChapterText       = b.ChapterText;
            val.PreviousChapterID = b.PreviousChapterID;

            return(val);
        }
        //public int PreviousChapterID { get; set; }


        public void SaveChapter()
        {
            if (string.IsNullOrEmpty(this.ChapterText))
            {
                return;
            }
            Models.Chapter c = new Models.Chapter();
            c.ChapterAddress = this.ChapterAddress;
            c.ChapterHTML    = Compression.CompressString(this.ChapterHtml);
            c.BookID         = this.BookID;
            c.ChapterName    = this.ChapterName;
            c.ChapterText    = Compression.CompressString(this.ChapterText);

            int itemp = 0;

            if (!string.IsNullOrEmpty(this.PreviousChapterAddress))
            {
                using (ReaderServiceSoapClient svc = new ReaderServiceSoapClient())
                {
                    itemp = svc.GetPreviousChapterID(ProgramStatics.Token, this.PreviousChapterAddress);// GetPreviousChapterID();
                }
            }
            c.PreviousChapterID = itemp;

            int id;

            using (ReaderServiceSoapClient svc = new ReaderServiceSoapClient())
            {
                id = svc.ChapterExists(ProgramStatics.Token, this.ChapterAddress);// ChapterExists();
            }

            if (id >= 0)
            {
                c.ChapterID = id;
                using (ReaderServiceSoapClient svc = new ReaderServiceSoapClient())
                {
                    svc.OverwriteChapter(ProgramStatics.Token, this.ChaptertoSvcChapter(c));// OverwriteChapter(id);
                }
            }
            else
            {
                using (ReaderServiceSoapClient svc = new ReaderServiceSoapClient())
                {
                    svc.InsertChapter(ProgramStatics.Token, this.ChaptertoSvcChapter(c));// InsertChapter();
                }
            }
        }