private static LearningResource CreateDxLearningResource(DbModel.LearningResource lr) { LearningResource dxLr = new LearningResource() { LearningResourceType = lr.LearningResourceType == null?"":lr.LearningResourceType.LearningResourceTypeName, Description = lr.Description, Title = lr.Title, PrimaryTechnologyName = lr.PrimaryTechnology == null?"":lr.PrimaryTechnology.PrimaryTech, PublicationTime = lr.PublicationTime, LearningResourceID = lr.LearningResourceID, Link = lr.ContentURL, Thumbnail = lr.ThumbnailURL }; dxLr.AudienceTypes = new List <AudienceType>(); foreach (var at in lr.AudienceTypes) { dxLr.AudienceTypes.Add(new AudienceType() { AudienceTypeId = at.AudienceTypeID, AudienceTypeName = at.TypeOfAudience }); } return(dxLr); }
public async Task <LearningResource> Add(LearningResource learningResource) { _context.LearningResources.Add(learningResource); await _context.SaveChangesAsync(); return(learningResource); }
private void NavigatedTo() { if (_parameter != null) { try { _resource = _parameter; var uri = new Uri(_resource.Link); this.WebView.Source = new UrlWebViewSource() { Url = _resource.Link.ToString() }; ((TechReady.ViewModels.LearnPageViewModel) this.BindingContext).Watched_Videos(_resource); this.ProgressBar.IsRunning = true; this.ProgressBar.IsVisible = true; } catch { this.ProgressBar.IsVisible = false; this.ProgressBar.IsRunning = false; this.ErrorMessage.IsVisible = true; } } }
public async Task <LearningResource> Update(LearningResource learningResource) { _context.Entry(learningResource).State = EntityState.Modified; await _context.SaveChangesAsync(); return(learningResource); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Url,ResourceListId,ContentFeedUrl")] LearningResource learningResource) { if (id != learningResource.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _learningResourceService.Update(learningResource); } catch (DbUpdateConcurrencyException) { if (!LearningResourceExists(learningResource.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } // var resourceList = await _resourceListService.Get(); ViewData["ResourceListId"] = new SelectList(resourceList, "Id", "Name", learningResource.ResourceListId); // return(View(learningResource)); }
public async Task <IActionResult> OnGetAsync(int id) { LearningResource = await _learningResourceService.Get(id); if (LearningResource == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int id) { LearningResource = await _learningResourceService.Get(id); if (LearningResource != null) { await _learningResourceService.Delete(id); } return(RedirectToPage("./Index")); }
public static async Task <ObservableCollection <LearningResource> > GetBlogs(string url) { try { RssFeed feed = null; await Task.Factory.StartNew( () => { try { feed = RssHelper.ReadFeed(new Uri(url)); } catch (Exception ex) { } }); ObservableCollection <LearningResource> learningResources = new ObservableCollection <LearningResource>(); if (feed == null) { return(null); } foreach (var item in feed.Items) { try { LearningResource v = new LearningResource(); v.Description = HtmlUtilities.ConvertToText(item.Description) .Replace("\n", "") .Replace("\r", ""); v.Link = item.Link; v.Title = item.Title; v.PublicationTime = item.PublicationUtcTime; learningResources.Add(v); } catch (Exception) { // } } return(learningResources); } catch (Exception ex) { return(null); } }
public LearnPage(LearningResource parameter) { this._parameter = parameter; this.Appearing += LearnPage_Appearing; shareToolbarItem = new ToolbarItem("Share", "Share.png", this.ShareEvent); this.ToolbarItems.Add(shareToolbarItem); InitializeComponent(); this.BindingContext = new TechReady.ViewModels.LearnPageViewModel(); }
public async Task <IActionResult> OnGetAsync(int id) { LearningResource = await _learningResourceService.Get(id); if (LearningResource == null) { return(NotFound()); } var resourceList = await _resourceListService.Get(); ViewData["ResourceListId"] = new SelectList(resourceList, "Id", "Name", LearningResource.ResourceListId); return(Page()); }
public async Task <IActionResult> Create([Bind("Id,Name,Url,ResourceListId,ContentFeedUrl")] LearningResource learningResource) { if (ModelState.IsValid) { await _learningResourceService.Add(learningResource); return(RedirectToAction(nameof(Index))); } var resourceList = await _resourceListService.Get(); ViewData["ResourceListId"] = new SelectList(resourceList, "Id", "Name", learningResource.ResourceListId); return(View(learningResource)); }
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 async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } LearningResource = await _context.LearningResource.FirstOrDefaultAsync(m => m.Id == id); if (LearningResource == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } LearningResource = await _context.LearningResource.FindAsync(id); if (LearningResource != null) { _context.LearningResource.Remove(LearningResource); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter != null) { _resource = JsonConvert.DeserializeObject <LearningResource>(e.Parameter as string); this.HeadingText.Text = _resource.Title; var uri = new Uri(_resource.Link); this.WebView.Navigate(uri); //((LearnPageViewModel)this.DataContext).Watched_Videos(_resource); DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView(); dataTransferManager.DataRequested += new TypedEventHandler <DataTransferManager, DataRequestedEventArgs>(this.DataRequested); } }
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); } }
// Please set the following connection strings in app.config for this WebJob to run: // AzureWebJobsDashboard and AzureWebJobsStorage private static void Main() { using (TechReadyDbContext ctx = new TechReadyDbContext()) { var feedsToCheck = (from c in ctx.LearningResourceFeeds select c).ToList(); foreach (var feedType in feedsToCheck) { XmlReader reader = XmlReader.Create(feedType.RSSLink, new XmlReaderSettings() { }); SyndicationFeed feed = SyndicationFeed.Load(reader); foreach (SyndicationItem i in feed.Items) { var link = i.Links[0].Uri.ToString(); if (ctx.LearningResources.FirstOrDefault(x => x.ContentURL == link) == null) { try { XmlSyndicationContent content = i.Content as XmlSyndicationContent; LearningResource lr = new LearningResource(); lr.Title = i.Title.Text; lr.AudienceTypes = new List <AudienceType>(); foreach (AudienceType a in feedType.AudienceTypes) { lr.AudienceTypes.Add(a); } lr.ContentURL = i.Links[0].Uri.ToString(); lr.LearningResourceTypeID = feedType.LearningResourceTypeID; lr.PrimaryTechnologyID = feedType.PrimaryTechnologyID; lr.PublicationTime = i.PublishDate.UtcDateTime; if (feedType.LearningResourceTypeID == 1) { lr.Description = GetExtensionElementValue <string>(i, "summary"); lr.ThumbnailURL = GetThumbnailChannel9(i); } else { lr.Description = i.Summary.Text; lr.ThumbnailURL = ""; } ctx.LearningResources.Add(lr); } catch { } } } } ctx.SaveChanges(); } }
public void Create([FromBody] LearningResource value) { _lrService.LearningResources.Add(value); _lrService.SaveChanges(); }
public void Update(string id, [FromBody] LearningResource value) { _lrService.LearningResources.Update(value); }