Files
InventoryTraker-Box/InventoryTraker.Web/Controllers/InventoryController.cs
T
2016-08-08 14:47:35 -04:00

44 lines
955 B
C#

using System.Linq;
using System.Web.Mvc;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Core;
using InventoryTraker.Web.Data;
using InventoryTraker.Web.Models;
namespace InventoryTraker.Web.Controllers
{
public class InventoryController : ControllerBase
{
private readonly AppDbContext _context;
public InventoryController(AppDbContext context)
{
_context = context;
}
public ActionResult Index()
{
return View();
}
public JsonResult All()
{
var customerModels = _context.Inventories
.OrderByDescending(x => x.InventoryType.Name)
.ProjectTo<InventoryViewModel>();
return BetterJson(customerModels.ToArray());
}
public JsonResult Arrival(AddCustomerForm form)
{
var customer = Mapper.Map<Customer>(form);
_context.Customers.Add(customer);
_context.SaveChanges();
var model = Mapper.Map<CustomerViewModel>(customer);
return BetterJson(model);
}
}
}