Skip to content

Commit

Permalink
Merge pull request #9 from shahedc/QueryTags
Browse files Browse the repository at this point in the history
Updated LearningResourceService to use QueryTag
  • Loading branch information
shahedc authored Apr 27, 2020
2 parents e9b6848 + 0328141 commit 451a585
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/NetLearner.Mvc/Controllers/LearningResourcesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public async Task<IActionResult> GetForList(int id)
return View("Index", await _learningResourceService.GetForList(id));
}

// GET: LearningResources
public async Task<IActionResult> GetTop(int topX)
{
return View("Index", await _learningResourceService.GetTop(topX));
}

// GET: LearningResources/Details/5
public async Task<IActionResult> Details(int id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface ILearningResourceService
{
Task<List<LearningResource>> Get();
Task<List<LearningResource>> GetForList(int id);
Task<List<LearningResource>> GetTop(int topX);
Task<LearningResource> Get(int id);
Task<LearningResource> Add(LearningResource learningResource);
Task<LearningResource> Update(LearningResource learningResource);
Expand Down
14 changes: 14 additions & 0 deletions src/NetLearner.SharedLib/Services/LearningResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public async Task<List<LearningResource>> Get()
return await _context.LearningResources.Include(r => r.ResourceList).ToListAsync();
}


public async Task<List<LearningResource>> GetTop(int topX)
{
var myItems =
(from m in _context.LearningResources
.Include(r => r.ResourceList)
.TagWith($"This retrieves top {topX} Items!")
orderby m.Id ascending
select m)
.Take(topX);

return (await myItems.ToListAsync());
}

public async Task<List<LearningResource>> GetForList(int resourceListId)
{
var results = _context.LearningResources
Expand Down

0 comments on commit 451a585

Please sign in to comment.