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(); return BetterJson(customerModels.ToArray()); } public JsonResult Arrival(AddCustomerForm form) { var customer = Mapper.Map(form); _context.Customers.Add(customer); _context.SaveChanges(); var model = Mapper.Map(customer); return BetterJson(model); } } }