public ActionResult Index(string commentatorCode, int chapterNumber, int verseNumber) { if (!QuranStructure.TryValidateChapterAndVerse(chapterNumber, verseNumber)) { return(HttpNotFound()); } CommentariesForVerse viewModel = CommentariesForVerseBuilder.Create( commentatorCode: commentatorCode, chapterNumber: chapterNumber, verseNumber: verseNumber); return(View("CommentariesForVerse", viewModel)); }
public CommentariesForVerse Create(string commentatorCode, int chapterNumber, int verseNumber) { Dictionary <string, Commentator> commentatorByCode = CommentatorRepository.GetAll() .ToDictionary(x => x.Code, StringComparer.InvariantCultureIgnoreCase); Chapter chapter = ChapterRepository.Get(chapterNumber); IEnumerable <Commentary> commentaries; if (string.IsNullOrEmpty(commentatorCode)) { commentaries = CommentaryRepository.GetForVerse(chapterNumber, verseNumber); } else { commentaries = new Commentary[] { CommentaryRepository.GetForVerse(commentatorCode, chapterNumber, verseNumber) } .Where(x => x != null); } IEnumerable <CommentatorAndCommentary> commentatorsAndCommentaries = commentaries .OrderBy(x => x.CommentatorCode) .Select( x => new CommentatorAndCommentary( commentator: commentatorByCode[x.CommentatorCode], commentary: x) ); var selectChapterAndVerse = new SelectChapterAndVerse( selectedChapterNumber: chapterNumber, selectedVerseNumber: verseNumber, url: "/Tafsirs"); var viewModel = new CommentariesForVerse( chapter: chapter, verseNumber: verseNumber, selectChapterAndVerse: selectChapterAndVerse, commentaries: commentatorsAndCommentaries); return(viewModel); }