Update automapper

This commit is contained in:
2016-09-24 00:06:34 -04:00
parent f473c64540
commit 6789c1b3b5
32 changed files with 254 additions and 206 deletions
@@ -1,6 +1,6 @@
using System.Collections;
using System.Linq;
using System.Linq;
using System.Web.Mvc;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Attributes;
using InventoryTraker.Web.Core;
@@ -12,10 +12,12 @@ namespace InventoryTraker.Web.Controllers
public class TransactionController : ControllerBase
{
private readonly AppDbContext _context;
private readonly IMapper _mapper;
public TransactionController(AppDbContext context)
public TransactionController(AppDbContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}
public ActionResult Index()
@@ -27,7 +29,7 @@ namespace InventoryTraker.Web.Controllers
{
var viewModels =
_context.Transactions
.ProjectTo<TransactionViewModel>()
.ProjectTo<TransactionViewModel>(_mapper.ConfigurationProvider)
.ToArray();
return BetterJson(viewModels);
@@ -50,7 +52,7 @@ namespace InventoryTraker.Web.Controllers
var totalItems = _context.Transactions.Count();
var transactions = query
.ProjectTo<TransactionViewModel>()
.ProjectTo<TransactionViewModel>(_mapper.ConfigurationProvider)
.ToArray();
return BetterJson(new { totalItems, transactions });
}