private void LoadCourses() { Courses = _repository.All().OrderByDescending(c => c.DateOfExamination) .Select(c => new CourseListItem(c)).ToArray(); State = Courses.Length > 0 ? CourseListState.Default : CourseListState.Empty; }
private static CourseListViewModel CreateViewModel( ICourseUpdater courseUpdater = null, ICourseRepository repository = null, IPreferencesUtility preferences = null, IDateTimeUtility dateTime = null, IDbConnection dbConnection = null, ISecureStorageUtility secureStorage = null, IBackgroundSyncUtility backgroundSync = null, IMessenger messenger = null ) { if (courseUpdater == null) { courseUpdater = Substitute.For <ICourseUpdater>(); courseUpdater.TryUpdateAsync().Returns( Task.FromResult(Result.WithSuccess(new CourseUpdateInfo(true))) ); } if (repository == null) { repository = Substitute.For <ICourseRepository>(); repository.All().Returns(new Course[0]); } var utcNow = DateTime.UtcNow; if (dateTime == null) { dateTime = Substitute.For <IDateTimeUtility>(); dateTime.UtcNow.Returns(utcNow); } if (preferences == null) { preferences = Substitute.For <IPreferencesUtility>(); preferences.LastCourseUpdateCheck.CompareTo(utcNow.AddMinutes(-30)); } dbConnection = dbConnection ?? Substitute.For <IDbConnection>(); secureStorage = secureStorage ?? Substitute.For <ISecureStorageUtility>(); backgroundSync = backgroundSync ?? Substitute.For <IBackgroundSyncUtility>(); messenger = messenger ?? Substitute.For <IMessenger>(); return(new CourseListViewModel( courseUpdater, repository, preferences, dateTime, dbConnection, secureStorage, backgroundSync, messenger )); }
public async Task <Result <CourseUpdateInfo> > TryUpdateAsync() { // Download the HTML page Result <string> downloadResult = await _downloader .TryDownloadCoursePageHtmlAsync(Constants.CareTranscriptOfRecordsUrl) .ConfigureAwait(false); if (!downloadResult.IsSuccessful) { return(downloadResult.ToResult <CourseUpdateInfo>()); } // Parse the HTML page var parseResult = _parser.TryParseCoursePage(downloadResult.Value); if (!parseResult.IsSuccessful) { return(parseResult.ToResult <CourseUpdateInfo>()); } // If we are good here we can remember the date time we last checked _preferences.LastCourseUpdateCheck = _dateTime.UtcNow; var existingCourses = _repository.All(); // Convert raw to actual courses var currentCourses = parseResult.Value.Select( rawCourse => Course.FromRawCourse( rawCourse, existingCourses.SingleOrDefault(ec => ec.Id == rawCourse.Id)?.DateOfLastUpdate ?? _dateTime.UtcNow ) ).ToArray(); // Compare our existing courses and our current ones. _comparer.Compare( existingCourses, currentCourses, out Course[] addedCourses, out Course[] modifiedCourses,
public async Task <IEnumerable <Course> > GetCourses() { return(await _courseRepository.All().ToListAsync()); }
public List <Course> All() { return(_courseRepository.All()); }
// GET: Courses public ActionResult Index() { //return View(db.Courses.ToList()); return(View("Index", cr.All())); }
private static CourseUpdater CreateCourseUpdater( ICoursePageHtmlDownloader downloader = null, ICoursePageHtmlParser parser = null, ICourseSetComparer comparer = null, ICourseRepository repository = null, IUnitOfWork unitOfWork = null, IDateTimeUtility dateTime = null, IPreferencesUtility preferences = null ) { if (downloader == null) { downloader = Substitute.For <ICoursePageHtmlDownloader>(); downloader.TryDownloadCoursePageHtmlAsync(Arg.Any <string>()) .Returns(Task.FromResult(Result.WithSuccess <string>())); } if (parser == null) { parser = Substitute.For <ICoursePageHtmlParser>(); parser.TryParseCoursePage(Arg.Any <string>()) .Returns(Result.WithSuccess(new RawCourse[0])); } if (repository == null) { repository = Substitute.For <ICourseRepository>(); repository.All().Returns(new Course[0]); } if (unitOfWork == null) { unitOfWork = Substitute.For <IUnitOfWork>(); var session = Substitute.For <IUnitOfWorkSession>(); unitOfWork.OpenSession().Returns(session); session.Commit().Returns(Result.Success); } if (dateTime == null) { dateTime = Substitute.For <IDateTimeUtility>(); dateTime.UtcNow.Returns(DateTime.UtcNow); } comparer = comparer ?? new CourseSetComparer(); preferences = preferences ?? Substitute.For <IPreferencesUtility>(); return(new CourseUpdater( downloader, parser, comparer, repository, unitOfWork, dateTime, preferences )); }