Update automapper
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user