From a5fcb46e045b976970ea5a9a220497827332e0e6 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Thu, 25 Aug 2016 13:00:09 -0400 Subject: [PATCH] InventoryType from XML Transaction updates --- .../Models/InventoryAddForm.cs | 2 +- .../ActionResults/BetterJsonResult.cs | 7 ++ InventoryTraker.Web/App_Start/SeedData.cs | 82 +++++++++++-------- .../Controllers/ControllerBase.cs | 2 +- .../Controllers/InventoryController.cs | 65 +++++++++++++-- .../Controllers/TransactionController.cs | 38 +++++++++ InventoryTraker.Web/Core/Transaction.cs | 3 + .../Helpers/AngularModelHelper.cs | 2 +- .../InventoryTraker.Web.csproj | 13 ++- .../Migrations/Configuration.cs | 6 +- .../Models/InventoryDistributeForm.cs | 28 +++++++ .../Models/InventoryViewModel.cs | 1 - .../Models/TransactionViewModel.cs | 46 +++++++++++ .../Utilities/InventoryTypeParser.cs | 1 - .../Views/Inventory/Index.cshtml | 12 ++- .../Views/Shared/_Navigation.cshtml | 7 +- .../Views/Transaction/Index.cshtml | 29 +++++++ InventoryTraker.Web/Web.config | 3 +- InventoryTraker.Web/css/layout.css | 4 +- .../js/inventory/InventoryAddDirective.js | 2 + .../inventory/InventoryDistributeDirective.js | 50 +++++++++++ .../js/inventory/InventoryListController.js | 9 ++ .../js/inventory/inventorySvc.js | 12 ++- .../templates/inventoryAdd.tmpl.cshtml | 4 +- .../templates/inventoryDistribute.tmpl.cshtml | 69 ++++++++++++++++ .../js/transaction/transactionSvc.js | 40 +++++++++ .../utility/FormGroupValidationDirective.js | 2 +- InventoryTraker.Web/packages.config | 2 +- 28 files changed, 471 insertions(+), 70 deletions(-) create mode 100644 InventoryTraker.Web/Controllers/TransactionController.cs create mode 100644 InventoryTraker.Web/Models/InventoryDistributeForm.cs create mode 100644 InventoryTraker.Web/Models/TransactionViewModel.cs create mode 100644 InventoryTraker.Web/Views/Transaction/Index.cshtml create mode 100644 InventoryTraker.Web/js/inventory/InventoryDistributeDirective.js create mode 100644 InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml create mode 100644 InventoryTraker.Web/js/transaction/transactionSvc.js diff --git a/InventoryTraker.Web.Tests/Models/InventoryAddForm.cs b/InventoryTraker.Web.Tests/Models/InventoryAddForm.cs index 2d1bb1e..05a4beb 100644 --- a/InventoryTraker.Web.Tests/Models/InventoryAddForm.cs +++ b/InventoryTraker.Web.Tests/Models/InventoryAddForm.cs @@ -24,7 +24,7 @@ namespace InventoryTraker.Web.Tests.Models { AddedDate = DateTime.Today, ExpirationDate = DateTime.Today.AddDays(3), - InventoryTypeId = "1", + InventoryTypeId = 1, Memo = "My Memo", Quantity = 32 }; diff --git a/InventoryTraker.Web/ActionResults/BetterJsonResult.cs b/InventoryTraker.Web/ActionResults/BetterJsonResult.cs index db85cda..8b3ceb5 100644 --- a/InventoryTraker.Web/ActionResults/BetterJsonResult.cs +++ b/InventoryTraker.Web/ActionResults/BetterJsonResult.cs @@ -21,6 +21,13 @@ namespace InventoryTraker.Web.ActionResults ErrorMessages.Add(errorMessage); } + public static BetterJsonResult Error(string errorMessage) + { + var betterJsonResult = new BetterJsonResult(); + betterJsonResult.AddError(errorMessage); + return betterJsonResult; + } + public override void ExecuteResult(ControllerContext context) { DoUninterestingBaseClassStuff(context); diff --git a/InventoryTraker.Web/App_Start/SeedData.cs b/InventoryTraker.Web/App_Start/SeedData.cs index 68e2eba..92f4e67 100644 --- a/InventoryTraker.Web/App_Start/SeedData.cs +++ b/InventoryTraker.Web/App_Start/SeedData.cs @@ -84,47 +84,59 @@ namespace InventoryTraker.Web private static void AddInventory(AppDbContext context) { - var pork = context.InventoryTypes.First(it => it.Identifier == "100139"); - var beans = context.InventoryTypes.First(it => it.Identifier == "100363"); - var pb = context.InventoryTypes.First(it => it.Identifier == "100395"); + var r = new Random(1); + var inventoryTypes = context.InventoryTypes.ToList(); - context.Inventories.Add(new Inventory + for (int i = 0; i < 100; i++) { - InventoryType = pork, - ExpirationDate = DateTime.Now.AddYears(1).AtMidnight(), - AddedDate = DateTime.Now.AddDays(-1).AtMidnight(), - Memo = "Hormel", - Quantity = 10, - Transactions = new List { new Transaction - { - AddedQuantity = 10, Memo = "arrival", TransactionDate = DateTime.Now.AddDays(-1).AtMidnight(), Timestamp = DateTime.Now - }} - }); + var inventoryType = inventoryTypes.ElementAt(r.Next(0, context.InventoryTypes.Count())); + var addedDate = DateTime.Today.AddMonths(-r.Next(1, 24)); + var expiration = addedDate.AddMonths(r.Next(12, 48)); + var memo = "New " + inventoryType.Name; + var quantity = r.Next(5, 112); - context.Inventories.Add(new Inventory - { - InventoryType = beans, - ExpirationDate = DateTime.Now.AddMonths(4).AtMidnight(), - AddedDate = DateTime.Now.AddMonths(-2).AtMidnight(), - Memo = "Cut", - Quantity = 15, - Transactions = new List { new Transaction + var previousTransaction = new Transaction { - AddedQuantity = 15, Memo = "arrival", TransactionDate = DateTime.Now.AddMonths(-2).AtMidnight(), Timestamp = DateTime.Now - }} - }); + AddedQuantity = quantity, Memo = "Arrival", CurrentQuantity = quantity, TransactionDate = addedDate, Timestamp = addedDate + }; + var inventory = new Inventory + { + InventoryType = inventoryType, + ExpirationDate = expiration, + AddedDate = addedDate, + Memo = memo, + Quantity = quantity, + Transactions = new List { previousTransaction} + }; + context.Inventories.Add(inventory); - context.Inventories.Add(new Inventory - { - InventoryType = pb, - ExpirationDate = DateTime.Now.AddDays(300).AtMidnight(), - AddedDate = DateTime.Now.AddDays(-34).AtMidnight(), - Quantity = 700, - Transactions = new List { new Transaction + for (int j = 0; j < 5 && previousTransaction.CurrentQuantity > 0; j++) { - AddedQuantity = 700, Memo = "arrival", TransactionDate = DateTime.Now.AddDays(-34).AtMidnight(), Timestamp = DateTime.Now - }} - }); + var transactionDate = previousTransaction.TransactionDate.AddDays(r.Next(1, 100)); + if (transactionDate >= DateTime.Today) + break; + + var quantityRemoved = r.Next(1, 100); + if (quantityRemoved > previousTransaction.CurrentQuantity) + quantityRemoved = previousTransaction.CurrentQuantity; + + var transaction = new Transaction + { + RemovedQuantity = quantityRemoved, + CurrentQuantity = previousTransaction.CurrentQuantity - quantityRemoved, + Inventory = inventory, + Memo = "Distributed", + TransactionDate = transactionDate, + Timestamp = transactionDate + }; + + inventory.Quantity = transaction.CurrentQuantity; + + inventory.Transactions.Add(transaction); + + previousTransaction = transaction; + } + } } private static void AddTerminatedCustomers(AppDbContext context) diff --git a/InventoryTraker.Web/Controllers/ControllerBase.cs b/InventoryTraker.Web/Controllers/ControllerBase.cs index 3efc08b..97316a8 100644 --- a/InventoryTraker.Web/Controllers/ControllerBase.cs +++ b/InventoryTraker.Web/Controllers/ControllerBase.cs @@ -8,7 +8,7 @@ namespace InventoryTraker.Web.Controllers { public BetterJsonResult BetterJson(T model) { - return new BetterJsonResult() {Data = model}; + return new BetterJsonResult {Data = model}; } protected JsonResult PackageModelStateErrors() diff --git a/InventoryTraker.Web/Controllers/InventoryController.cs b/InventoryTraker.Web/Controllers/InventoryController.cs index 148fd85..0bfd247 100644 --- a/InventoryTraker.Web/Controllers/InventoryController.cs +++ b/InventoryTraker.Web/Controllers/InventoryController.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web.Mvc; using AutoMapper; using AutoMapper.QueryableExtensions; +using InventoryTraker.Web.ActionResults; using InventoryTraker.Web.Core; using InventoryTraker.Web.Data; using InventoryTraker.Web.Models; @@ -26,14 +27,22 @@ namespace InventoryTraker.Web.Controllers public JsonResult All() { - var viewModels = _context.Inventories - .OrderBy(x => x.InventoryType.Name) + var viewModels = + AllInventory() .ProjectTo() .ToArray(); return BetterJson(viewModels); } + private IQueryable AllInventory() + { + return _context + .Inventories + .Where(x => x.Quantity > 0) + .OrderBy(x => x.InventoryType.Name); + } + public JsonResult Add(InventoryAddForm form) { if (!ModelState.IsValid) @@ -42,18 +51,56 @@ namespace InventoryTraker.Web.Controllers var inventory = Mapper.Map(form); inventory.InventoryType = _context.InventoryTypes.Find(form.InventoryTypeId); _context.Inventories.Add(inventory); - inventory.Transactions = new List(); - inventory.Transactions.Add(new Transaction + inventory.Transactions = new List { - AddedQuantity = inventory.Quantity, - Memo = "Arrival", - Timestamp = DateTime.Now, - TransactionDate = inventory.AddedDate - }); + new Transaction + { + AddedQuantity = inventory.Quantity, + CurrentQuantity = inventory.Quantity, + Memo = "Arrival", + Timestamp = DateTime.Now, + TransactionDate = inventory.AddedDate + } + }; _context.SaveChanges(); var model = Mapper.Map(inventory); return BetterJson(model); } + + public JsonResult Distribute(InventoryDistributeForm form) + { + if (!ModelState.IsValid) + return PackageModelStateErrors(); + + foreach (var quantityForm in form.InventoryQuantities) + { + var inventory = _context.Inventories.Find(quantityForm.InventoryId); + + // check if it's really there + if (inventory == null) + return BetterJsonResult.Error($"Inventory {quantityForm.InventoryId} not found"); + + if (inventory.Quantity < quantityForm.Quantity) + return BetterJsonResult.Error( + $"Inventory {inventory.InventoryType.Name} has only {inventory.Quantity}, trying to remove {quantityForm.Quantity}"); + inventory.Quantity -= quantityForm.Quantity; + + inventory.Transactions.Add(new Transaction + { + RemovedQuantity = quantityForm.Quantity, + CurrentQuantity = inventory.Quantity, + Memo = "Distributed to " + form.Destination, + Timestamp = DateTime.Now, + TransactionDate = form.DistributedDate + }); + } + + _context.SaveChanges(); + + return BetterJson(AllInventory() + .ProjectTo() + .ToArray()); + } } } \ No newline at end of file diff --git a/InventoryTraker.Web/Controllers/TransactionController.cs b/InventoryTraker.Web/Controllers/TransactionController.cs new file mode 100644 index 0000000..fb08545 --- /dev/null +++ b/InventoryTraker.Web/Controllers/TransactionController.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web.Mvc; +using AutoMapper; +using AutoMapper.QueryableExtensions; +using InventoryTraker.Web.ActionResults; +using InventoryTraker.Web.Core; +using InventoryTraker.Web.Data; +using InventoryTraker.Web.Models; + +namespace InventoryTraker.Web.Controllers +{ + public class TransactionController : ControllerBase + { + private readonly AppDbContext _context; + + public TransactionController(AppDbContext context) + { + _context = context; + } + + public ActionResult Index() + { + return View(); + } + + public JsonResult All() + { + var viewModels = + _context.Transactions + .ProjectTo() + .ToArray(); + + return BetterJson(viewModels); + } + } +} \ No newline at end of file diff --git a/InventoryTraker.Web/Core/Transaction.cs b/InventoryTraker.Web/Core/Transaction.cs index 5814e7a..7bc45be 100644 --- a/InventoryTraker.Web/Core/Transaction.cs +++ b/InventoryTraker.Web/Core/Transaction.cs @@ -15,6 +15,9 @@ namespace InventoryTraker.Web.Core [Required] public int RemovedQuantity { get; set; } + [Required] + public int CurrentQuantity { get; set; } + [Required] public DateTime TransactionDate { get; set; } diff --git a/InventoryTraker.Web/Helpers/AngularModelHelper.cs b/InventoryTraker.Web/Helpers/AngularModelHelper.cs index 434a237..c27277d 100644 --- a/InventoryTraker.Web/Helpers/AngularModelHelper.cs +++ b/InventoryTraker.Web/Helpers/AngularModelHelper.cs @@ -123,7 +123,7 @@ namespace InventoryTraker.Web.Helpers { //input.Attr("type", "date"); input.Attr("bs-datepicker"); - input.Attr("data-date-format", "d/M/yyyy"); + input.Attr("data-date-format", "M/d/yyyy"); } if (metadata.DataTypeName == "PhoneNumber") diff --git a/InventoryTraker.Web/InventoryTraker.Web.csproj b/InventoryTraker.Web/InventoryTraker.Web.csproj index 8d19e03..cc93a40 100644 --- a/InventoryTraker.Web/InventoryTraker.Web.csproj +++ b/InventoryTraker.Web/InventoryTraker.Web.csproj @@ -52,7 +52,7 @@ True - ..\packages\CsvHelper.2.11.0\lib\net40-client\CsvHelper.dll + ..\packages\CsvHelper.2.16.0.0\lib\net45\CsvHelper.dll True @@ -238,6 +238,7 @@ + @@ -247,6 +248,7 @@ + @@ -282,6 +284,7 @@ PreserveNewest + @@ -304,6 +307,7 @@ + @@ -335,6 +339,7 @@ + @@ -351,6 +356,7 @@ + @@ -380,6 +386,7 @@ + Web.config @@ -387,9 +394,7 @@ Web.config - - - + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/InventoryTraker.Web/Migrations/Configuration.cs b/InventoryTraker.Web/Migrations/Configuration.cs index df689e9..ba22c1d 100644 --- a/InventoryTraker.Web/Migrations/Configuration.cs +++ b/InventoryTraker.Web/Migrations/Configuration.cs @@ -8,9 +8,11 @@ namespace InventoryTraker.Web.Migrations public Configuration() { AutomaticMigrationsEnabled = true; - } + // TODO false + AutomaticMigrationDataLossAllowed = true; + } - protected override void Seed(AppDbContext context) + protected override void Seed(AppDbContext context) { } diff --git a/InventoryTraker.Web/Models/InventoryDistributeForm.cs b/InventoryTraker.Web/Models/InventoryDistributeForm.cs new file mode 100644 index 0000000..7fd7c6e --- /dev/null +++ b/InventoryTraker.Web/Models/InventoryDistributeForm.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace InventoryTraker.Web.Models +{ + public class InventoryQuantityForm + { + [Required] + public int InventoryId { get; set; } + + [Required, Range(1, int.MaxValue, ErrorMessage = "Quantity must be greater than 0")] + public int Quantity { get; set; } + } + + public class InventoryDistributeForm + { + public IList InventoryQuantities { get; set; } + + [Required] + public string Destination { get; set; } + + [Required, Display(Name = "Distributed Date")] + public DateTime DistributedDate { get; set; } + + public string Memo { get; set; } + } +} \ No newline at end of file diff --git a/InventoryTraker.Web/Models/InventoryViewModel.cs b/InventoryTraker.Web/Models/InventoryViewModel.cs index c22dabe..14ed27f 100644 --- a/InventoryTraker.Web/Models/InventoryViewModel.cs +++ b/InventoryTraker.Web/Models/InventoryViewModel.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using AutoMapper; using Heroic.AutoMapper; using InventoryTraker.Web.Core; diff --git a/InventoryTraker.Web/Models/TransactionViewModel.cs b/InventoryTraker.Web/Models/TransactionViewModel.cs new file mode 100644 index 0000000..f2760f7 --- /dev/null +++ b/InventoryTraker.Web/Models/TransactionViewModel.cs @@ -0,0 +1,46 @@ +using System; +using System.ComponentModel.DataAnnotations; +using AutoMapper; +using Heroic.AutoMapper; +using InventoryTraker.Web.Core; + +namespace InventoryTraker.Web.Models +{ + public class TransactionViewModel : IMapFrom, IHaveCustomMappings + { + [Required] + public int Id { get; set; } + + public string Name { get; set; } + public int UnitsPerCase { get; set; } + public string ContainerType { get; set; } + + [Required] + public int AddedQuantity { get; set; } + + [Required] + public int RemovedQuantity { get; set; } + + [Required] + public int CurrentQuantity { get; set; } + + [Required] + public DateTime TransactionDate { get; set; } + + public string Memo { get; set; } + + [Required] + public DateTime Timestamp { get; set; } + + public void CreateMappings(IMapperConfiguration configuration) + { + configuration.CreateMap() + .ForMember(d => d.Name, + opt => opt.MapFrom(s => s.Inventory.InventoryType.Name)) + .ForMember(d => d.UnitsPerCase, + opt => opt.MapFrom(s => s.Inventory.InventoryType.UnitsPerCase)) + .ForMember(d => d.ContainerType, + opt => opt.MapFrom(s => s.Inventory.InventoryType.ContainerType)); + } + } +} \ No newline at end of file diff --git a/InventoryTraker.Web/Utilities/InventoryTypeParser.cs b/InventoryTraker.Web/Utilities/InventoryTypeParser.cs index d20d586..6dfe304 100644 --- a/InventoryTraker.Web/Utilities/InventoryTypeParser.cs +++ b/InventoryTraker.Web/Utilities/InventoryTypeParser.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using ClosedXML.Excel; using CsvHelper.Configuration; using InventoryTraker.Web.Core; diff --git a/InventoryTraker.Web/Views/Inventory/Index.cshtml b/InventoryTraker.Web/Views/Inventory/Index.cshtml index 9a3481f..68e0418 100644 --- a/InventoryTraker.Web/Views/Inventory/Index.cshtml +++ b/InventoryTraker.Web/Views/Inventory/Index.cshtml @@ -5,9 +5,13 @@ }
-

- Inventory - -

+

+ Inventory +

+ +
\ No newline at end of file diff --git a/InventoryTraker.Web/Views/Shared/_Navigation.cshtml b/InventoryTraker.Web/Views/Shared/_Navigation.cshtml index 673a85c..d23b3bf 100644 --- a/InventoryTraker.Web/Views/Shared/_Navigation.cshtml +++ b/InventoryTraker.Web/Views/Shared/_Navigation.cshtml @@ -26,8 +26,11 @@ diff --git a/InventoryTraker.Web/Views/Transaction/Index.cshtml b/InventoryTraker.Web/Views/Transaction/Index.cshtml new file mode 100644 index 0000000..fef592c --- /dev/null +++ b/InventoryTraker.Web/Views/Transaction/Index.cshtml @@ -0,0 +1,29 @@ +@using InventoryTraker.Web.Helpers +@using InventoryTraker.Web.Models +@model dynamic + +@{ + ViewBag.Title = "Inventory"; +} + +
+

+ Transactions +

+ + + @(Html.Angular().GridFor(c => c.All()) + .Title("Transactions") + .Columns(config => + { + config.Add(x => x.Name); + config.Add(x => x.Memo); + config.Add(x => x.TransactionDate, "Transaction Date", "date: 'MM/dd/yyyy'"); + config.Add(x => x.AddedQuantity, "Add Qty"); + config.Add(x => x.RemovedQuantity, "Remove Qty"); + config.Add(x => x.CurrentQuantity); + })) +
\ No newline at end of file diff --git a/InventoryTraker.Web/Web.config b/InventoryTraker.Web/Web.config index 6b5fdb9..48f7c48 100644 --- a/InventoryTraker.Web/Web.config +++ b/InventoryTraker.Web/Web.config @@ -102,4 +102,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/InventoryTraker.Web/css/layout.css b/InventoryTraker.Web/css/layout.css index d43e6db..abd50c2 100644 --- a/InventoryTraker.Web/css/layout.css +++ b/InventoryTraker.Web/css/layout.css @@ -97,6 +97,6 @@ textarea { border-radius: 50%; } -.has-feedback ng-transclude ~ input-validation-icons .form-control-feedback { +/*.has-feedback ng-transclude ~ input-validation-icons .form-control-feedback { top: 26px; -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/InventoryTraker.Web/js/inventory/InventoryAddDirective.js b/InventoryTraker.Web/js/inventory/InventoryAddDirective.js index 6124137..e6c8817 100644 --- a/InventoryTraker.Web/js/inventory/InventoryAddDirective.js +++ b/InventoryTraker.Web/js/inventory/InventoryAddDirective.js @@ -12,6 +12,7 @@ } controller.$inject = ['$scope', 'inventorySvc', 'inventoryTypeSvc']; + function controller($scope, inventorySvc, inventoryTypeSvc) { var vm = this; @@ -19,6 +20,7 @@ vm.saving = false; vm.inventory = {}; vm.inventoryTypes = inventoryTypeSvc.inventoryTypes; + vm.errorMessage = null; vm.quantity = quantity; diff --git a/InventoryTraker.Web/js/inventory/InventoryDistributeDirective.js b/InventoryTraker.Web/js/inventory/InventoryDistributeDirective.js new file mode 100644 index 0000000..b2960f1 --- /dev/null +++ b/InventoryTraker.Web/js/inventory/InventoryDistributeDirective.js @@ -0,0 +1,50 @@ +(function() { + "use strict"; + + window.app.directive('inventoryDistribute', inventoryDistribute); + + function inventoryDistribute() { + return { + templateUrl: '/inventory/template/inventoryDistribute.tmpl.cshtml', + controller: controller, + controllerAs: 'vm' + } + } + + controller.$inject = ['$scope', 'inventorySvc']; + function controller($scope, inventorySvc) { + var vm = this; + + vm.save = save; + vm.saving = false; + vm.quantities = angular.copy(inventorySvc.inventories); + vm.distribution = {}; + vm.errorMessage = null; + + function getInventoryDistributeQuantities(inventory) { + var invQty = []; + inventory.forEach(function (i) { + if (i.distributeQuantity > 0) + invQty.push({ inventoryId: i.id, quantity: i.distributeQuantity }); + }); + return invQty; + } + + function save() { + vm.saving = true; + vm.distribution.inventoryQuantities = getInventoryDistributeQuantities(vm.quantities); + inventorySvc.distribute(vm.distribution) + .success(function () { + //Close the modal + $scope.$close(); + }) + .error(function(data) { + vm.errorMessage = + 'There was a problem distributing the inventory: ' + data.errorMessage; + }) + .finally(function() { + vm.saving = false; + }); + } + } +})(); \ No newline at end of file diff --git a/InventoryTraker.Web/js/inventory/InventoryListController.js b/InventoryTraker.Web/js/inventory/InventoryListController.js index 7f72fe9..5bd24cc 100644 --- a/InventoryTraker.Web/js/inventory/InventoryListController.js +++ b/InventoryTraker.Web/js/inventory/InventoryListController.js @@ -6,7 +6,9 @@ InventoryListController.$inject = ['$uibModal', 'inventorySvc']; function InventoryListController($uibModal, inventorySvc) { var vm = this; + vm.add = add; + vm.distribute = distribute; vm.inventories = inventorySvc.inventories; function add() { @@ -15,5 +17,12 @@ backdrop: 'static' }); } + + function distribute() { + $uibModal.open({ + template: '', + backdrop: 'static' + }); + } } })(); \ No newline at end of file diff --git a/InventoryTraker.Web/js/inventory/inventorySvc.js b/InventoryTraker.Web/js/inventory/inventorySvc.js index 55ae0b1..7a4a2f1 100644 --- a/InventoryTraker.Web/js/inventory/inventorySvc.js +++ b/InventoryTraker.Web/js/inventory/inventorySvc.js @@ -9,9 +9,10 @@ var svc = { add: add, + distribute: distribute, update: update, inventories: inventories, - getInventory: getInventory, + getInventory: getInventory }; return svc; @@ -19,7 +20,7 @@ function loadInventories() { $http.post('/Inventory/All') .success(function(data) { - inventories.addRange(data); + angular.copy(data, inventories); }); } @@ -30,6 +31,13 @@ }); } + function distribute(distribution) { + return $http.post('/Inventory/Distribute', distribution) + .success(function (data) { + angular.copy(data, inventories); + }); + } + function update(existingInventory, updatedInventory) { return $http.post('/Inventory/Update', updatedInventory) .success(function(inventory) { diff --git a/InventoryTraker.Web/js/inventory/templates/inventoryAdd.tmpl.cshtml b/InventoryTraker.Web/js/inventory/templates/inventoryAdd.tmpl.cshtml index 8dfe205..a2a216b 100644 --- a/InventoryTraker.Web/js/inventory/templates/inventoryAdd.tmpl.cshtml +++ b/InventoryTraker.Web/js/inventory/templates/inventoryAdd.tmpl.cshtml @@ -27,7 +27,7 @@ -
+
m.ExpirationDate) -
+
diff --git a/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml b/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml new file mode 100644 index 0000000..dd314e2 --- /dev/null +++ b/InventoryTraker.Web/js/inventory/templates/inventoryDistribute.tmpl.cshtml @@ -0,0 +1,69 @@ +@using InventoryTraker.Web.Helpers +@model InventoryTraker.Web.Models.InventoryDistributeForm +@{ + var distribution = Html.Angular().ModelFor("vm.distribution"); +} +
+
+ + + + + + + +
+
\ No newline at end of file diff --git a/InventoryTraker.Web/js/transaction/transactionSvc.js b/InventoryTraker.Web/js/transaction/transactionSvc.js new file mode 100644 index 0000000..7e5dfca --- /dev/null +++ b/InventoryTraker.Web/js/transaction/transactionSvc.js @@ -0,0 +1,40 @@ +(function() { + window.app.factory('transactionSvc', transactionSvc); + + transactionSvc.$inject = ['$http']; + function transactionSvc($http) { + var transactions = []; + + loadTransactions(); + + var svc = { + add: add, + update: update, + transactions: transactions, + getTransaction: getTransaction + }; + + return svc; + + function loadTransactions() { + $http.post('/Transaction/All') + .success(function(data) { + angular.copy(data, transactions); + }); + } + + function update(existingTransaction, updatedTransaction) { + return $http.post('/Transaction/Update', updatedTransaction) + .success(function(transaction) { + angular.extend(existingTransaction, transaction); + }); + } + + function getTransaction(id) { + for (var i = 0; i < transactions.length; i++) { + if (transactions[i].Id == id) return transactions[i]; + } + return null; + } + } +})(); \ No newline at end of file diff --git a/InventoryTraker.Web/js/utility/FormGroupValidationDirective.js b/InventoryTraker.Web/js/utility/FormGroupValidationDirective.js index f6f3d28..51530f7 100644 --- a/InventoryTraker.Web/js/utility/FormGroupValidationDirective.js +++ b/InventoryTraker.Web/js/utility/FormGroupValidationDirective.js @@ -11,7 +11,7 @@ template: '
' + '' + - '' + + //'' + '
', scope: { field: '@formGroupValidation' diff --git a/InventoryTraker.Web/packages.config b/InventoryTraker.Web/packages.config index 053c902..4b72d1e 100644 --- a/InventoryTraker.Web/packages.config +++ b/InventoryTraker.Web/packages.config @@ -9,7 +9,7 @@ - +