Initiate InventoyTypes from a xlxs

Arrival mostly working
This commit is contained in:
2016-08-22 11:03:00 -04:00
parent 7e4d8a6d2a
commit 53ed1b3af9
40 changed files with 798 additions and 208 deletions
@@ -38,7 +38,7 @@ namespace InventoryTraker.Web.Controllers
var identity = _userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
_authManager.SignIn(new AuthenticationProperties { IsPersistent = false }, identity);
_authManager.SignIn(new AuthenticationProperties { IsPersistent = true }, identity);
return Json(true);
}
@@ -1,4 +1,5 @@
using System.Web.Mvc;
using System.Linq;
using System.Web.Mvc;
using InventoryTraker.Web.ActionResults;
namespace InventoryTraker.Web.Controllers
@@ -9,5 +10,16 @@ namespace InventoryTraker.Web.Controllers
{
return new BetterJsonResult<T>() {Data = model};
}
protected JsonResult PackageModelStateErrors()
{
var betterJsonResult = new BetterJsonResult();
foreach (var err in ModelState.Where(ms => ms.Value.Errors.Any()))
{
betterJsonResult.AddError(
err.Key + ": " + string.Join(", ", err.Value.Errors.Select(e => e.ErrorMessage)));
}
return betterJsonResult;
}
}
}
@@ -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);
@@ -0,0 +1,27 @@
using System.Linq;
using System.Web.Mvc;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Data;
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());
}
}
}