Changed use of custom SmartJsonResult to JsonResult in MusicStore.Spa
This commit is contained in:
parent
2934514909
commit
4a4fe86df4
|
|
@ -19,43 +19,37 @@ namespace MusicStore.Apis
|
||||||
//[Route("api/albums")]
|
//[Route("api/albums")]
|
||||||
public async Task<ActionResult> Paged(int page = 1, int pageSize = 50, string sortBy = null)
|
public async Task<ActionResult> Paged(int page = 1, int pageSize = 50, string sortBy = null)
|
||||||
{
|
{
|
||||||
var pagedAlbums = await _storeContext.Albums
|
var albums = await _storeContext.Albums
|
||||||
//.Include(a => a.Genre)
|
//.Include(a => a.Genre)
|
||||||
//.Include(a => a.Artist)
|
//.Include(a => a.Artist)
|
||||||
.SortBy(sortBy, a => a.Title)
|
.SortBy(sortBy, a => a.Title)
|
||||||
.ToPagedListAsync(page, pageSize);
|
.ToPagedListAsync(page, pageSize);
|
||||||
|
|
||||||
return new SmartJsonResult
|
return Json(albums);
|
||||||
{
|
|
||||||
Data = pagedAlbums
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Route("api/albums/all")]
|
//[Route("api/albums/all")]
|
||||||
public async Task<ActionResult> All()
|
public async Task<ActionResult> All()
|
||||||
{
|
{
|
||||||
return new SmartJsonResult
|
var albums = await _storeContext.Albums
|
||||||
{
|
//.Include(a => a.Genre)
|
||||||
Data = await _storeContext.Albums
|
//.Include(a => a.Artist)
|
||||||
//.Include(a => a.Genre)
|
.OrderBy(a => a.Title)
|
||||||
//.Include(a => a.Artist)
|
.ToListAsync();
|
||||||
.OrderBy(a => a.Title)
|
|
||||||
.ToListAsync()
|
return Json(albums);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Route("api/albums/mostPopular")]
|
//[Route("api/albums/mostPopular")]
|
||||||
public async Task<ActionResult> MostPopular(int count = 6)
|
public async Task<ActionResult> MostPopular(int count = 6)
|
||||||
{
|
{
|
||||||
count = count > 0 && count < 20 ? count : 6;
|
count = count > 0 && count < 20 ? count : 6;
|
||||||
|
var albums = await _storeContext.Albums
|
||||||
|
.OrderByDescending(a => a.OrderDetails.Count())
|
||||||
|
.Take(count)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
return new SmartJsonResult
|
return Json(albums);
|
||||||
{
|
|
||||||
Data = await _storeContext.Albums
|
|
||||||
.OrderByDescending(a => a.OrderDetails.Count())
|
|
||||||
.Take(count)
|
|
||||||
.ToListAsync()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Route("api/albums/{albumId:int}")]
|
//[Route("api/albums/{albumId:int}")]
|
||||||
|
|
@ -73,10 +67,7 @@ namespace MusicStore.Apis
|
||||||
|
|
||||||
// TODO: Add null checking and return 404 in that case
|
// TODO: Add null checking and return 404 in that case
|
||||||
|
|
||||||
return new SmartJsonResult
|
return Json(album);
|
||||||
{
|
|
||||||
Data = album
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Route("api/albums")]
|
//[Route("api/albums")]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
|
|
@ -19,10 +18,11 @@ namespace MusicStore.Apis
|
||||||
//[Route("api/artists/lookup")]
|
//[Route("api/artists/lookup")]
|
||||||
public async Task<ActionResult> Lookup()
|
public async Task<ActionResult> Lookup()
|
||||||
{
|
{
|
||||||
return new SmartJsonResult
|
var artists = await _storeContext.Artists
|
||||||
{
|
.OrderBy(a => a.Name)
|
||||||
Data = await _storeContext.Artists.OrderBy(a => a.Name).ToListAsync()
|
.ToListAsync();
|
||||||
};
|
|
||||||
|
return Json(artists);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,12 +17,11 @@ namespace MusicStore.Apis
|
||||||
//[Route("api/genres/lookup")]
|
//[Route("api/genres/lookup")]
|
||||||
public async Task<ActionResult> Lookup()
|
public async Task<ActionResult> Lookup()
|
||||||
{
|
{
|
||||||
return new SmartJsonResult
|
var genres = await _storeContext.Genres
|
||||||
{
|
.Select(g => new { g.GenreId, g.Name })
|
||||||
Data = await _storeContext.Genres
|
.ToListAsync();
|
||||||
.Select(g => new { g.GenreId, g.Name })
|
|
||||||
.ToListAsync()
|
return Json(genres);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Route("api/genres/menu")]
|
//[Route("api/genres/menu")]
|
||||||
|
|
@ -30,25 +29,25 @@ namespace MusicStore.Apis
|
||||||
{
|
{
|
||||||
count = count > 0 && count < 20 ? count : 9;
|
count = count > 0 && count < 20 ? count : 9;
|
||||||
|
|
||||||
return new SmartJsonResult
|
var genres = await _storeContext.Genres
|
||||||
{
|
.OrderByDescending(g =>
|
||||||
Data = await _storeContext.Genres
|
g.Albums.Sum(a =>
|
||||||
.OrderByDescending(g => g.Albums.Sum(a => a.OrderDetails.Sum(od => od.Quantity)))
|
a.OrderDetails.Sum(od => od.Quantity)))
|
||||||
.Take(count)
|
.Take(count)
|
||||||
.ToListAsync()
|
.ToListAsync();
|
||||||
};
|
|
||||||
|
return Json(genres);
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Route("api/genres")]
|
//[Route("api/genres")]
|
||||||
public async Task<ActionResult> GenreList()
|
public async Task<ActionResult> GenreList()
|
||||||
{
|
{
|
||||||
return new SmartJsonResult
|
var genres = await _storeContext.Genres
|
||||||
{
|
//.Include(g => g.Albums)
|
||||||
Data = await _storeContext.Genres
|
.OrderBy(g => g.Name)
|
||||||
//.Include(g => g.Albums)
|
.ToListAsync();
|
||||||
.OrderBy(g => g.Name)
|
|
||||||
.ToListAsync()
|
return Json(genres);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Route("api/genres/{genreId:int}/albums")]
|
//[Route("api/genres/{genreId:int}/albums")]
|
||||||
|
|
@ -61,10 +60,7 @@ namespace MusicStore.Apis
|
||||||
//.OrderBy(a => a.Genre.Name)
|
//.OrderBy(a => a.Genre.Name)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
return new SmartJsonResult
|
return Json(albums);
|
||||||
{
|
|
||||||
Data = albums
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
|
@ -18,10 +17,10 @@ namespace Microsoft.AspNet.Mvc
|
||||||
Message = "The model submitted was invalid. Please correct the specified errors and try again.";
|
Message = "The model submitted was invalid. Please correct the specified errors and try again.";
|
||||||
ModelErrors = modelState
|
ModelErrors = modelState
|
||||||
.SelectMany(m => m.Value.Errors.Select(me => new ModelError
|
.SelectMany(m => m.Value.Errors.Select(me => new ModelError
|
||||||
{
|
{
|
||||||
FieldName = m.Key,
|
FieldName = m.Key,
|
||||||
ErrorMessage = me.ErrorMessage
|
ErrorMessage = me.ErrorMessage
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,11 +42,12 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
public override void ExecuteResult(ActionContext context)
|
public override void ExecuteResult(ActionContext context)
|
||||||
{
|
{
|
||||||
var json = new SmartJsonResult
|
if (StatusCode.HasValue)
|
||||||
{
|
{
|
||||||
StatusCode = StatusCode,
|
context.HttpContext.Response.StatusCode = StatusCode.Value;
|
||||||
Data = this
|
}
|
||||||
};
|
|
||||||
|
var json = new JsonResult(this);
|
||||||
json.ExecuteResult(context);
|
json.ExecuteResult(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue