Files
InventoryTraker-Box/InventoryTraker.Web/js/inventory/inventorySvc.js
T
poprhythm a5fcb46e04 InventoryType from XML
Transaction updates
2016-08-25 13:00:09 -04:00

56 lines
1.2 KiB
JavaScript

(function() {
window.app.factory('inventorySvc', inventorySvc);
inventorySvc.$inject = ['$http'];
function inventorySvc($http) {
var inventories = [];
loadInventories();
var svc = {
add: add,
distribute: distribute,
update: update,
inventories: inventories,
getInventory: getInventory
};
return svc;
function loadInventories() {
$http.post('/Inventory/All')
.success(function(data) {
angular.copy(data, inventories);
});
}
function add(inventory) {
return $http.post('/Inventory/Add', inventory)
.success(function(inventory) {
inventories.unshift(inventory);
});
}
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) {
angular.extend(existingInventory, inventory);
});
}
function getInventory(id) {
for (var i = 0; i < inventories.length; i++) {
if (inventories[i].Id == id) return inventories[i];
}
return null;
}
}
})();