private Slide GetInitialSlideForStartup(string courseId, List <Unit> orderedVisibleUnits, bool isInstructor) { var userId = User.Identity.GetUserId(); var lastVisit = visitsRepo.FindLastVisit(courseId, userId); var orderedVisibleSlides = orderedVisibleUnits.SelectMany(u => u.GetSlides(isInstructor)).ToList(); if (lastVisit != null) { var lastVisitedSlide = orderedVisibleSlides.FirstOrDefault(s => s.Id == lastVisit.SlideId); if (lastVisitedSlide != null) { return(lastVisitedSlide); } if (isInstructor) { var instructorNoteSlide = orderedVisibleUnits.FirstOrDefault(u => u.Id == lastVisit.SlideId)?.InstructorNote?.Slide; if (instructorNoteSlide != null) { return(instructorNoteSlide); } } } var unorderedVisitedIds = visitsRepo.GetIdOfVisitedSlides(courseId, userId); var lastVisitedVisibleSlide = orderedVisibleSlides.LastOrDefault(slide => unorderedVisitedIds.Contains(slide.Id)); if (lastVisitedVisibleSlide != null) { return(lastVisitedVisibleSlide); } return(orderedVisibleSlides.Any() ? orderedVisibleSlides.First() : null); }