public async Task <IActionResult> GetGenre( [FromQuery] int?id, [FromQuery] string name) { _logger.LogDebug("GetGenre"); Genre genre = null; if (id.HasValue) { genre = await DbContext.Genres .Include(g => g.Albums) .Where(g => g.GenreId == id.Value) .FirstOrDefaultAsync(); } else { genre = await DbContext.Genres .Include(g => g.Albums) .Where(g => g.Name == name) .FirstOrDefaultAsync(); } if (genre == null) { return(NotFound()); } var result = GenreJson.From(genre); return(new ObjectResult(result)); }
public async Task <List <GenreJson> > GetGenres() { var genres = await DbContext.Genres .Include(g => g.Albums) .ToListAsync(); return(GenreJson.From(genres)); }