filter licenses by implemented

This commit is contained in:
Collin M. Barrett 2018-09-27 20:13:16 -05:00
parent be29d16eb3
commit b9cb2c4e7e
2 changed files with 12 additions and 10 deletions

View file

@ -18,12 +18,12 @@ public LicensesController(IMemoryCache memoryCache, SeedService seedService, Lic
[HttpGet]
public async Task<IActionResult> GetAll() =>
await Get(() => licenseService.GetAllAsync());
await Get(() => licenseService.GetAllImplementedAsync());
[HttpGet]
[Route("{id}")]
public async Task<IActionResult> GetById(int id) =>
await Get(() => licenseService.GetByIdAsync(id), id);
await Get(() => licenseService.GetImplementedByIdAsync(id), id);
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
@ -17,14 +18,15 @@ public LicenseService(FilterListsDbContext dbContext, IConfigurationProvider map
{
}
public async Task<IEnumerable<LicenseDto>> GetAllAsync() =>
await DbContext.Licenses
.ProjectTo<LicenseDto>(MapConfig)
.ToListAsync();
private IQueryable<Data.Entities.License> ImplementedLicenses =>
DbContext.Licenses.Where(l => l.FilterLists.Any());
public async Task<LicenseDto> GetByIdAsync(int id) =>
await DbContext.Licenses
.ProjectTo<LicenseDto>(MapConfig)
.FirstOrDefaultAsync(l => l.Id == id);
public async Task<IEnumerable<LicenseDto>> GetAllImplementedAsync() =>
await ImplementedLicenses.ProjectTo<LicenseDto>(MapConfig)
.ToListAsync();
public async Task<LicenseDto> GetImplementedByIdAsync(int id) =>
await ImplementedLicenses.ProjectTo<LicenseDto>(MapConfig)
.FirstOrDefaultAsync(l => l.Id == id);
}
}