Initiate InventoyTypes from a xlxs
Arrival mostly working
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
@@ -8,25 +10,6 @@ using InventoryTraker.Web.Models;
|
||||
|
||||
namespace InventoryTraker.Web.Controllers
|
||||
{
|
||||
public class InventoryTypeController : ControllerBase
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public InventoryTypeController(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public JsonResult All()
|
||||
{
|
||||
var viewModels = _context.InventoryTypes
|
||||
.OrderByDescending(x => x.Name)
|
||||
.ProjectTo<InventoryTypeViewModel>();
|
||||
|
||||
return BetterJson(viewModels.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public class InventoryController : ControllerBase
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
@@ -44,7 +27,7 @@ namespace InventoryTraker.Web.Controllers
|
||||
public JsonResult All()
|
||||
{
|
||||
var viewModels = _context.Inventories
|
||||
.OrderByDescending(x => x.InventoryType.Name)
|
||||
.OrderBy(x => x.InventoryType.Name)
|
||||
.ProjectTo<InventoryViewModel>()
|
||||
.ToArray();
|
||||
|
||||
@@ -53,9 +36,20 @@ namespace InventoryTraker.Web.Controllers
|
||||
|
||||
public JsonResult Add(InventoryAddForm form)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return PackageModelStateErrors();
|
||||
|
||||
var inventory = Mapper.Map<Inventory>(form);
|
||||
inventory.InventoryType = _context.InventoryTypes.Find(form.InventoryTypeId);
|
||||
_context.Inventories.Add(inventory);
|
||||
inventory.Transactions = new List<Transaction>();
|
||||
inventory.Transactions.Add(new Transaction
|
||||
{
|
||||
AddedQuantity = inventory.Quantity,
|
||||
Memo = "Arrival",
|
||||
Timestamp = DateTime.Now,
|
||||
TransactionDate = inventory.AddedDate
|
||||
});
|
||||
_context.SaveChanges();
|
||||
|
||||
var model = Mapper.Map<InventoryViewModel>(inventory);
|
||||
|
||||
Reference in New Issue
Block a user