mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Initial state
This commit is contained in:
70
samples/angular/MusicStore/Apis/GenresApiController.cs
Normal file
70
samples/angular/MusicStore/Apis/GenresApiController.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using MusicStore.Models;
|
||||
using MusicStore.Infrastructure;
|
||||
|
||||
namespace MusicStore.Apis
|
||||
{
|
||||
[Route("api/genres")]
|
||||
public class GenresApiController : Controller
|
||||
{
|
||||
private readonly MusicStoreContext _storeContext;
|
||||
|
||||
public GenresApiController(MusicStoreContext storeContext)
|
||||
{
|
||||
_storeContext = storeContext;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> GenreList()
|
||||
{
|
||||
var genres = await _storeContext.Genres
|
||||
//.Include(g => g.Albums)
|
||||
.OrderBy(g => g.Name)
|
||||
.ToListAsync();
|
||||
|
||||
return Json(genres);
|
||||
}
|
||||
|
||||
[HttpGet("genre-lookup")]
|
||||
public async Task<ActionResult> Lookup()
|
||||
{
|
||||
var genres = await _storeContext.Genres
|
||||
.Select(g => new { g.GenreId, g.Name })
|
||||
.ToListAsync();
|
||||
|
||||
return Json(genres);
|
||||
}
|
||||
|
||||
[HttpGet("menu")]
|
||||
public async Task<ActionResult> GenreMenuList(int count = 9)
|
||||
{
|
||||
count = count > 0 && count < 20 ? count : 9;
|
||||
|
||||
var genres = await _storeContext.Genres
|
||||
.OrderByDescending(g =>
|
||||
g.Albums.Sum(a =>
|
||||
a.OrderDetails.Sum(od => od.Quantity)))
|
||||
.Take(count)
|
||||
.ToListAsync();
|
||||
|
||||
return Json(genres);
|
||||
}
|
||||
|
||||
[HttpGet("{genreId:int}/albums")]
|
||||
[NoCache]
|
||||
public async Task<ActionResult> GenreAlbums(int genreId)
|
||||
{
|
||||
var albums = await _storeContext.Albums
|
||||
.Where(a => a.GenreId == genreId)
|
||||
//.Include(a => a.Genre)
|
||||
//.Include(a => a.Artist)
|
||||
//.OrderBy(a => a.Genre.Name)
|
||||
.ToListAsync();
|
||||
|
||||
return Json(albums);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user