// GET: CourseChapters/Details/5 public async Task <IActionResult> Details(Guid?id) { ViewData["CourseChapterId"] = id; //if (id == null) //{ // return NotFound(); //} //var courseChapter = await _context.CourseChapters // .Include(c => c.Course) // .SingleOrDefaultAsync(m => m.Id == id); //if (courseChapter == null) //{ // return NotFound(); //} //return View(courseChapter); CourseChapterViewModel CourseChapreVM = new CourseChapterViewModel() { CourseChapter = await _context.CourseChapters .Include(c => c.Course) .SingleOrDefaultAsync(m => m.Id == id), CourseChapterContents = _context.CourseChapterContents.Where(a => a.CourseChapterId == id).OrderBy(a => a.Indx).Include(a => a.CourseChapter) }; return(View(CourseChapreVM)); }
// GET: CourseChapters public async Task <IActionResult> Index(string SearchString, int coid, int productPage = 1) { CourseChapterViewModel CourseChapterVM = new CourseChapterViewModel(); if (string.IsNullOrEmpty(SearchString)) { CourseChapterVM = new CourseChapterViewModel() { CourseChapters = _context.CourseChapters.Where(a => a.CourseId == coid).OrderBy(a => a.Indx).Include(p => p.Course), }; } else if (!string.IsNullOrEmpty(SearchString)) { CourseChapterVM = new CourseChapterViewModel() { CourseChapters = _context.CourseChapters.Where(a => a.CourseId == coid).Where(a => a.Name.Contains(SearchString) || a.Course.ArName.Contains(SearchString)).OrderBy(a => a.Indx).Include(p => p.Course), }; } var count = CourseChapterVM.CourseChapters.Count(); CourseChapterVM.CourseChapters = CourseChapterVM.CourseChapters.OrderBy(p => p.Id) .Skip((productPage - 1) * PagSize) .Take(PagSize).ToList(); CourseChapterVM.PagingInfo = new PagingInfo { CurrentPage = productPage, ItemsPerPage = PagSize, TotalItem = count }; return(View(CourseChapterVM)); //var aRIDDbContext = _context.CourseChapters.Include(c => c.Course); //return View(await aRIDDbContext.ToListAsync()); }