Пример #1
0
        public string GetList(int bookId, int start = 1, int length = 50, SortType sort = 0, bool includeCount = false)
        {
            if (!CheckSecurity())
            {
                return(AccessDenied());
            }
            var html        = new StringBuilder();
            var entries     = new Scaffold("/Services/Entries/entries.html", S.Server.Scaffold);
            var item        = new Scaffold("/Services/Entries/list-item.html", S.Server.Scaffold);
            var chapter     = new Scaffold("/Services/Entries/chapter.html", S.Server.Scaffold);
            var books       = new Query.Books(S.Server.sqlConnectionString);
            var query       = new Query.Entries(S.Server.sqlConnectionString);
            var chapters    = new Query.Chapters(S.Server.sqlConnectionString);
            var chapterlist = chapters.GetList(bookId);
            var list        = query.GetList(S.User.userId, bookId, start, length, (int)sort);
            var chapterInc  = -1;
            var book        = books.GetDetails(S.User.userId, bookId);

            entries.Data["book-title"] = book.title;

            if (list.Count > 0)
            {
                list.ForEach((Query.Models.Entry entry) =>
                {
                    if (chapterInc != entry.chapter && sort == 0)
                    {
                        if (entry.chapter > 0)
                        {
                            //display chapter
                            chapter.Data["chapter"] = "Chapter " + entry.chapter.ToString() + ": " +
                                                      chapterlist.Find((Query.Models.Chapter c) => { return(c.chapter == entry.chapter); }).title;
                            html.Append(chapter.Render());
                        }
                        chapterInc = entry.chapter;
                    }
                    item.Data["id"]           = entry.entryId.ToString();
                    item.Data["title"]        = entry.title;
                    item.Data["summary"]      = entry.summary;
                    item.Data["date-created"] = entry.datecreated.ToString("d/MM/yyyy");
                    html.Append(item.Render());
                });
                entries.Data["entries"] = html.ToString();
            }
            else
            {
                html.Append(S.Server.LoadFileFromCache("/Services/Entries/no-entries.html"));
            }

            return((includeCount == true ? list.Count + "|" : "") + entries.Render());
        }