public async Task FilterLearningResources(string type, string technology, string role) { this.SelectedType = type ?? ""; this.SelectedRole = role ?? ""; this.SelectedTechnology = technology ?? ""; ObservableCollection <LearningResource> model; model = await LearningResourceService.GetLearningResourcesFromLocal(); if (model == null) { await MessageHelper.ShowMessage("Please connect to internet to download learning resources"); return; } var list = (from c in model where (this.SelectedTechnology == "" || SelectedTechnology == "All" || c.PrimaryTechnologyName == this.SelectedTechnology) && (SelectedRole == "" || SelectedRole == "All" || c.AudienceTypes.FirstOrDefault(x => x.AudienceTypeName == SelectedRole) != null) && (SelectedType == "" || SelectedType == "All" || c.LearningResourceType == SelectedType) select c).ToList(); this.AllLearningResources = new ObservableCollection <LearningResource>(list); this.ShowAll = true; }
public async Task GetLearningResources() { this.AllResources = await LearningResourceService.GetLearningResourcesFromLocal(); OnPropertyChanged("Technologies"); OnPropertyChanged("Types"); OnPropertyChanged("Roles"); }
private async Task SetLearningContent(ObservableCollection <LearningResource> model) { if (model != null) { var usermodel = await LocalStorage.ReadJsonFromFile <UserRegistrationPageViewModel>("registration"); if (usermodel != null) { foreach (LearningResource rs in model) { if ( rs.AudienceTypes.FirstOrDefault( x => x.AudienceTypeName == usermodel.SelectedAudienceType.AudienceTypeName) != null) { rs.Weitage++; } if ( usermodel.SecondaryTechnologies.FirstOrDefault( x => x.PrimaryTechnologyName == rs.PrimaryTechnologyName) != null) { rs.Weitage++; } } model = new ObservableCollection <LearningResource>(model.OrderByDescending(x => x.Weitage)); await LearningResourceService.SaveLearningResources(model); this.AllLearningResources = model; var recomendedresources = new ObservableCollection <LearningResource>(model.OrderByDescending(x => x.Weitage).ToList()); if (AllLearningResources.Count > 5) { recomendedresources = new ObservableCollection <LearningResource>(recomendedresources.Take(5)); recomendedresources.Add(new LoadMoreLearningResource()); } else { recomendedresources = AllLearningResources; } this.RecommendedLearningResources = recomendedresources; OnPropertyChanged("AllLearningResources"); OnPropertyChanged("RecommendedLearningResources"); } } }
public void CreateLearningResource() { var sds = new ServiceDescriptionService(DevConnectionStrings.MongoConnectionString); var result = sds.ObjectCollection.Find(p => p.ServiceName == "Host groups"); LearningResource lr = new LearningResource() { Name = "Cool document", ServiceID = result.FirstOrDefault().Id, Uri = new System.Uri("http://cooldoc") }; LearningResourceService lrs = new LearningResourceService(DevConnectionStrings.MongoConnectionString); lrs.Insert(lr); }
public void CreateLearningResourceWithTransactionShouldFail() { var sds = new ServiceDescriptionService(DevConnectionStrings.MongoConnectionString); var result = sds.ObjectCollection.Find(p => p.ServiceName == "Host groups"); LearningResource lr = new LearningResource() { Name = "Cool document", ServiceID = "", Uri = new System.Uri("http://cooldoc") }; LearningResourceService lrs = new LearningResourceService(DevConnectionStrings.MongoConnectionString); bool res = lrs.InsertAndUpdateService(lr); if (res != false) { //TODO how to correctly fail a test? throw new System.Exception("Test failed"); } }
public async void TestAdd(string expectedName) { var options = new DbContextOptionsBuilder <LibDbContext>() .UseInMemoryDatabase(databaseName: "TestNewResourceDb").Options; // Set up a context (connection to the "DB") for writing using (var context = new LibDbContext(options)) { // 1. Arrange var rl = new ResourceList { Name = "RL1" }; var lr = new LearningResource { Name = "LR1", Url = "https://somedomain.com", ResourceList = rl }; // 2. Act var lrs = new LearningResourceService(context); await lrs.Add(lr); } using (var context = new LibDbContext(options)) { var lrs = new LearningResourceService(context); var result = await lrs.Get(); // 3. Assert Assert.NotEmpty(result); Assert.Single(result); Assert.NotEmpty(result.First().Name); Assert.Equal(expectedName, result.First().Name); } }
public async Task GetLearningContent() { this.OperationInProgress = true; try { LearningResourcesRequest request = new LearningResourcesRequest() { RequestedPageNo = 1, SourceType = "All", Technologies = new List <string>(), UserRole = "All" }; ObservableCollection <LearningResource> model = await LearningResourceService.GetLearningResourcesFromLocal(); await SetLearningContent(model); if (NetworkHelper.IsNetworkAvailable() == false) { if (model == null) { await MessageHelper.ShowMessage("Please connect to internet to download learning resources"); return; } } else { var result = await LearningResourceService.GetLearningResourcesFromServer(request); if (result != null) { model = result; await LearningResourceService.SaveLearningResources(model); } else { //await MessageHelper.ShowMessage(result.Error.Message); } } var favVideos = await LocalStorage.ReadJsonFromFile <ObservableCollection <LearningResource> >("watchedVideos"); foreach (var flr in favVideos) { var lr = model.Where(x => x.LearningResourceID == flr.LearningResourceID).FirstOrDefault(); if (lr != null) { lr.Favourited = true; } } await SetLearningContent(model); } catch (Exception) { } finally { this.OperationInProgress = false; } }