Changed use of custom SmartJsonResult to JsonResult in MusicStore.Spa

This commit is contained in:
DamianEdwards 2014-06-16 15:55:50 -07:00
parent 2934514909
commit 4a4fe86df4
4 changed files with 49 additions and 62 deletions

View File

@ -19,43 +19,37 @@ namespace MusicStore.Apis
//[Route("api/albums")]
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.Artist)
.SortBy(sortBy, a => a.Title)
.ToPagedListAsync(page, pageSize);
return new SmartJsonResult
{
Data = pagedAlbums
};
return Json(albums);
}
//[Route("api/albums/all")]
public async Task<ActionResult> All()
{
return new SmartJsonResult
{
Data = await _storeContext.Albums
//.Include(a => a.Genre)
//.Include(a => a.Artist)
.OrderBy(a => a.Title)
.ToListAsync()
};
var albums = await _storeContext.Albums
//.Include(a => a.Genre)
//.Include(a => a.Artist)
.OrderBy(a => a.Title)
.ToListAsync();
return Json(albums);
}
//[Route("api/albums/mostPopular")]
public async Task<ActionResult> MostPopular(int 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
{
Data = await _storeContext.Albums
.OrderByDescending(a => a.OrderDetails.Count())
.Take(count)
.ToListAsync()
};
return Json(albums);
}
//[Route("api/albums/{albumId:int}")]
@ -73,10 +67,7 @@ namespace MusicStore.Apis
// TODO: Add null checking and return 404 in that case
return new SmartJsonResult
{
Data = album
};
return Json(album);
}
//[Route("api/albums")]

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
@ -19,10 +18,11 @@ namespace MusicStore.Apis
//[Route("api/artists/lookup")]
public async Task<ActionResult> Lookup()
{
return new SmartJsonResult
{
Data = await _storeContext.Artists.OrderBy(a => a.Name).ToListAsync()
};
var artists = await _storeContext.Artists
.OrderBy(a => a.Name)
.ToListAsync();
return Json(artists);
}
}
}

View File

@ -17,12 +17,11 @@ namespace MusicStore.Apis
//[Route("api/genres/lookup")]
public async Task<ActionResult> Lookup()
{
return new SmartJsonResult
{
Data = await _storeContext.Genres
.Select(g => new { g.GenreId, g.Name })
.ToListAsync()
};
var genres = await _storeContext.Genres
.Select(g => new { g.GenreId, g.Name })
.ToListAsync();
return Json(genres);
}
//[Route("api/genres/menu")]
@ -30,25 +29,25 @@ namespace MusicStore.Apis
{
count = count > 0 && count < 20 ? count : 9;
return new SmartJsonResult
{
Data = await _storeContext.Genres
.OrderByDescending(g => g.Albums.Sum(a => a.OrderDetails.Sum(od => od.Quantity)))
.Take(count)
.ToListAsync()
};
var genres = await _storeContext.Genres
.OrderByDescending(g =>
g.Albums.Sum(a =>
a.OrderDetails.Sum(od => od.Quantity)))
.Take(count)
.ToListAsync();
return Json(genres);
}
//[Route("api/genres")]
public async Task<ActionResult> GenreList()
{
return new SmartJsonResult
{
Data = await _storeContext.Genres
//.Include(g => g.Albums)
.OrderBy(g => g.Name)
.ToListAsync()
};
var genres = await _storeContext.Genres
//.Include(g => g.Albums)
.OrderBy(g => g.Name)
.ToListAsync();
return Json(genres);
}
//[Route("api/genres/{genreId:int}/albums")]
@ -61,10 +60,7 @@ namespace MusicStore.Apis
//.OrderBy(a => a.Genre.Name)
.ToListAsync();
return new SmartJsonResult
{
Data = albums
};
return Json(albums);
}
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ModelBinding;
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.";
ModelErrors = modelState
.SelectMany(m => m.Value.Errors.Select(me => new ModelError
{
FieldName = m.Key,
ErrorMessage = me.ErrorMessage
}));
{
FieldName = m.Key,
ErrorMessage = me.ErrorMessage
}));
}
}
@ -43,11 +42,12 @@ namespace Microsoft.AspNet.Mvc
public override void ExecuteResult(ActionContext context)
{
var json = new SmartJsonResult
if (StatusCode.HasValue)
{
StatusCode = StatusCode,
Data = this
};
context.HttpContext.Response.StatusCode = StatusCode.Value;
}
var json = new JsonResult(this);
json.ExecuteResult(context);
}