Beispiel #1
0
        public IQueryable <ChapterStoryVM> GetChaptersByRange(string slug, int start, int end)
        {
            IQueryable <Chapter> chapters = from c in db.Chapters
                                            where c.Story.Slug.Equals(slug)
                                            orderby c.ChapterNumber
                                            select c;
            List <ChapterStoryVM> chapterVMs = new List <ChapterStoryVM>();
            ChapterStoryVM        chapterVM;

            int total = chapters.Count();

            if (start < 1 || (start > end && start < total) || start > total)
            {
                start = 1;
                end   = 0;
            }

            if (end > total)
            {
                end = total;
            }

            int begin = start - 1;

            foreach (var chapter in chapters.Skip(begin).Take(end - begin))
            {
                chapterVM = new ChapterStoryVM(chapter);
                chapterVMs.Add(chapterVM);
            }

            return(chapterVMs.AsQueryable());
        }
Beispiel #2
0
        public IQueryable <ChapterStoryVM> GetChaptersBySearch(string story, string keyword)
        {
            string name = keyword;
            int    number;

            int.TryParse(keyword, out number);
            string[] keywords = keyword.Split(' ');
            if (keywords.Length > 0)
            {
                int.TryParse(keywords[keywords.Length - 1], out number);
            }
            IQueryable <Chapter> chapters =
                db.Chapters.Where(
                    c => c.Story.Slug.Equals(story) && (c.ChapterTitle.Contains(name) || c.ChapterNumber == number));
            List <ChapterStoryVM> chapterVMs = new List <ChapterStoryVM>();
            ChapterStoryVM        chapterVM;

            foreach (var chapter in chapters)
            {
                chapterVM = new ChapterStoryVM(chapter);
                chapterVMs.Add(chapterVM);
            }

            return(chapterVMs.AsQueryable());
        }