Example #1
0
    public async Task AddChapterAsync()
    {
        Console.WriteLine(nameof(AddChapterAsync));
        var chapter  = new BookChapter(Guid.NewGuid(), 25, "Services", 40);
        var response = await _httpClient.PostAsJsonAsync(_booksApiUri, chapter);

        Console.WriteLine($"status code: {response.StatusCode}");
        Console.WriteLine($"created at location: {response.Headers.Location?.AbsolutePath}");
        Console.WriteLine();
    }
 public IActionResult PostBookChapter([FromBody] BookChapter chapter)
 {
     if (chapter == null)
     {
         return(HttpBadRequest());
     }
     _repository.Add(chapter);
     // return a 201 response, Created
     return(CreatedAtRoute(nameof(GetBookChapterById), new { id = chapter.Id }, chapter));
 }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            long         id  = WS.RequestString("id").ToInt64();
            DataEntities ent = new DataEntities();
            BookChapter  c   = (from l in ent.BookChapter where l.ID == id select l).FirstOrDefault();

            ent.Dispose();
            Response.Clear();
            Response.Write(Voodoo.IO.XML.Serialize(c));
        }
        public async Task <IActionResult> PostBookChapterAsync([FromBody] BookChapter chapter)
        {
            if (chapter == null)
            {
                return(BadRequest());
            }
            await _bookChaptersService.AddAsync(chapter);

            return(CreatedAtRoute(nameof(GetBookChapterByIdAsync), new { id = chapter.Id }, chapter));
        }
    public async Task <ActionResult> PostBookChapter(BookChapter chapter)
    {
        if (chapter is null)
        {
            return(BadRequest());
        }
        await _chapterService.AddAsync(chapter);

        return(CreatedAtRoute(nameof(GetBookChapterById), new { id = chapter.Id }, chapter));
    }
Example #6
0
 private static ChapterModel CreateChapter(string bookId, BookChapter chapter, IList <TokenBase> tokens)
 {
     return(new ChapterModel
     {
         BookID = bookId,
         Level = chapter.Level,
         Title = chapter.Title.Length > 1024 ? chapter.Title.Substring(0, 1024) : chapter.Title,
         TokenID = GetUIToken(chapter.TokenID, tokens),
         MinTokenID = GetMinToken(chapter.TokenID, tokens)
     });
 }
        private async void Refresh(uint id)
        {
            chapter = await bookApi.GetChapterAsync(id);

            if (chapter == null)
            {
                return;
            }
            mainPage.Text = chapter.Content;
            mainPage.Go();
        }
        private void ProcessTitleData(TokenIndex top, XElement xelement, int bookLevel)
        {
            var item = new BookChapter
            {
                Level   = bookLevel,
                Title   = GetText(xelement),
                TokenID = top.Index
            };

            _chapters.Add(item);
        }
Example #9
0
        protected void ChapterError(string ChapterID)
        {
            BookChapter chapter = BookChapterView.GetModelByID(ChapterID);

            chapter.IsTemp         = true;
            chapter.IsImageChapter = true;
            BookChapterView.Update(chapter);

            Response.Clear();
            Response.Write(chapter.ToJsonStr());
        }
Example #10
0
        /// <summary>
        /// 获取章节内容
        /// </summary>
        /// <param name="chapterID">章节id</param>
        protected void GetChapterContent(long chapterID)
        {
            BookChapter chapter = BookChapterView.GetModelByID(chapterID.ToS());

            string path = BasePage.GetBookChapterTxtUrl(chapter, BookView.GetClass(chapter));

            string content = Voodoo.IO.File.Read(Server.MapPath(path));

            Response.Clear();
            Response.Write(XML.Serialize(content));
        }
Example #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DataEntities ent = new DataEntities();

                long        chapterid = WS.RequestString("cid").ToInt64();
                BookChapter bc        = (from l in ent.BookChapter where l.ID == chapterid select l).FirstOrDefault();
                bc.ClickCount = bc.ClickCount > 0 ? bc.ClickCount + 1 : 1;

                ent.SaveChanges();

                ent.Dispose();
                //写入Cookie

                List <Cook> cookies = new List <Cook>();
                if (Voodoo.Cookies.Cookies.GetCookie("history") != null)
                {
                    string[] chapters = Voodoo.Cookies.Cookies.GetCookie("history").Value.Split(',');
                    foreach (string chapter in chapters)
                    {
                        string[] arr_chapter = chapter.Split('|');
                        cookies.Add(new Cook()
                        {
                            id = arr_chapter[0].ToInt64(), time = arr_chapter[1].ToDateTime(), bookid = arr_chapter[2].ToInt32()
                        });
                    }
                }

                cookies = cookies.Where(p => p.bookid != bc.BookID).OrderByDescending(p => p.time).Take(4).ToList();
                cookies.Add(new Cook()
                {
                    id = chapterid, time = DateTime.Now, bookid = bc.BookID
                });

                StringBuilder sb = new StringBuilder();

                foreach (Cook c in cookies)
                {
                    sb.Append(string.Format("{0}|{1}|{2},", c.id, c.time.ToString(), c.bookid.ToS()));
                }
                sb = sb.TrimEnd(',');

                HttpCookie _cookie = new HttpCookie("history", sb.ToString());
                _cookie.Expires = DateTime.Now.AddYears(1);

                Voodoo.Cookies.Cookies.SetCookie(_cookie);
            }//end try
            catch
            {
                Voodoo.Cookies.Cookies.Remove("history");
            }
        }
 // PUT: api/BookChapters/5
 //public void PutBookChapter(int id, [FromBody]BookChapter value)
 //{
 //    chapters.Remove(chapters.Where(b => b.Number == id).SingleOrDefault());
 //    chapters.Add(value);
 //}
 public IHttpActionResult PutBookChapter(int id, [FromBody] BookChapter value)
 {
     try {
         chapters.Remove(chapters.Where(b => b.Number == id).SingleOrDefault());
         chapters.Add(value);
         return(Ok());
     }
     catch (InvalidOperationException)
     {
         return(BadRequest());
     }
 }
 public IActionResult PostBookChapter([FromBody] BookChapter chapter)
 {
     //如果参数BookChapter为空,则返回BadRequest(HTTP错误400)
     if (chapter == null)
     {
         return(BadRequest());
     }
     _bookChaptersService.Add(chapter);
     // CreatedAtRoute返回HTTP状态201(已创建),并且对象已序列化。
     // 返回的头信息包含指向资源的链接,即指向GetBookChapterById的链接,其id设置为新创建的对象的标识符
     return(CreatedAtRoute(nameof(GetBookChapterById), new { id = chapter.Id }, chapter));
 }
Example #14
0
        // PUT api/bookchapter/5
        public IHttpActionResult PutBookChapter(int id, [FromBody] BookChapter value)
        {
            BookChapter bookChapter = Chapters.SingleOrDefault(chapter => chapter.Number == id);

            if (bookChapter != null)
            {
                bookChapter.Title = value.Title;
                bookChapter.Pages = value.Pages;
                return(Ok());
            }

            return(BadRequest());
        }
Example #15
0
        /// <summary>
        /// 获取下一章节
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static BookChapter GetNextChapter(BookChapter cp, Book b)
        {
            List <BookChapter> lresult = BookChapterView.GetModelList(string.Format("BookID={0} and ID>{1} order by ID Asc", b.ID, cp.ID), 1);

            if (lresult.Count == 0)
            {
                return(null);
            }
            else
            {
                return(lresult.First());
            }
        }
 public IActionResult PutBookChapter(Guid id, [FromBody] BookChapter chapter)
 {
     if (chapter == null || id != chapter.Id)
     {
         return(BadRequest());
     }
     if (_bookChaptersService.Find(id) == null)
     {
         return(NotFound());
     }
     _bookChaptersService.Update(chapter);
     return(new NoContentResult());
 }
Example #17
0
        /// <summary>
        /// System.Net.Http.Formatting
        /// </summary>
        /// <returns></returns>
        private static async Task ReadWithExtensionsSample()
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:8019");
            HttpResponseMessage response =
                await client.GetAsync("/api/BookChapters/3");

            BookChapter chapter =
                await response.Content.ReadAsAsync <BookChapter>();

            Console.WriteLine("{0}. {1}", chapter.Number, chapter.Title);
        }
Example #18
0
        public async Task UpdateChapterAsync(BookChapter chapter)
        {
            //Console.WriteLine(nameof(UpdateChapterAsync));
            //var chapters = await _bookChapterClientService.GetAllAsync(_urlService.BookApi);
            //var chapter = chapters.SingleOrDefault(c => c.Title == "WXG");
            //if (chapter != null)
            //{
            //    chapter.Title = "WXG! Hello World!";
            await _bookChapterClientService.PutAsync(_urlService.BookApi + chapter.Id, chapter);

            Debug.WriteLine($"updated chapter {chapter.Title}");
            //}
        }
Example #19
0
        /// <summary>
        /// 获取章节内容
        /// </summary>
        /// <param name="chapterID">章节id</param>
        protected void GetChapterContent(long chapterID)
        {
            using (DataEntities ent = new DataEntities())
            {
                BookChapter chapter = (from l in ent.BookChapter where l.ID == chapterID select l).FirstOrDefault();

                string path = BasePage.GetBookChapterTxtUrl(chapter, chapter.GetClass());

                string content = Voodoo.IO.File.Read(Server.MapPath(path));
                Response.Clear();
                Response.Write(XML.Serialize(content));
            }
        }
        public async Task <IActionResult> GetBookChapterByIdAsync(Guid id)
        {
            BookChapter chapter = await _repository.FindAsync(id);

            if (chapter == null)
            {
                return(HttpNotFound());
            }
            else
            {
                return(new ObjectResult(chapter));
            }
        }
        public async Task <IActionResult> GetBookChapterByIdAsync(Guid id)
        {
            BookChapter chapter = await _bookChaptersService.FindAsync(id);

            if (chapter == null)
            {
                return(NotFound());
            }
            else
            {
                return(new ObjectResult(chapter));
            }
        }
Example #22
0
 // PUT api/bookchapters/5
 public IHttpActionResult PutBookChapter(int id, [FromBody] BookChapter value)
 {
     try
     {
         chapters.Remove(chapters.Where(c => c.Number == id).Single());
         chapters.Add(value);
         return(Ok());
     }
     catch (InvalidOperationException) // chapter does not exist
     {
         return(BadRequest());
     }
 }
Example #23
0
        /// <summary>
        /// 获取问答url地址
        /// </summary>
        /// <param name="qs"></param>
        /// <param name="cls"></param>
        /// <returns></returns>
        public string GetBookChapterUrl(BookChapter cp, Class cls)
        {
            DataEntities ent = new DataEntities();

            string result = "";
            string fileName = cp.ID.ToString();

            Book b = (from l in ent.Book where l.ID == cp.BookID select l).FirstOrDefault();

            string sitrurl = "/Book/";

            result = string.Format("{0}{1}/{2}/{3}{4}",
                sitrurl,
                cls.ClassForder,
                 b.Title + "-" + b.Author,
                cp.ID,
                BasePage.SystemSetting.ExtName
                );
            result = Regex.Replace(result, "[/]{2,}", "/");
            return result;
        }
Example #24
0
 /// <summary>
 /// 获取章节txt文件路径
 /// </summary>
 /// <param name="cp"></param>
 /// <param name="cls"></param>
 /// <returns></returns>
 public string GetBookChapterTxtUrl(BookChapter cp, Class cls)
 {
     return cp.TxtPath;
 }
Example #25
0
 public void AddToBookChapter(BookChapter bookChapter)
 {
     base.AddObject("BookChapter", bookChapter);
 }
Example #26
0
 public static BookChapter CreateBookChapter(long id, int bookID, long classID, long valumeID, global::System.DateTime updateTime, int chapterIndex)
 {
     BookChapter bookChapter = new BookChapter();
     bookChapter.ID = id;
     bookChapter.BookID = bookID;
     bookChapter.ClassID = classID;
     bookChapter.ValumeID = valumeID;
     bookChapter.UpdateTime = updateTime;
     bookChapter.ChapterIndex = chapterIndex;
     return bookChapter;
 }