Intial
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
(function() {
|
||||
window.app.factory('inventorySvc', inventorySvc);
|
||||
|
||||
inventorySvc.$inject = ['$http'];
|
||||
function inventorySvc($http) {
|
||||
var inventories = [];
|
||||
|
||||
loadInventories();
|
||||
|
||||
var svc = {
|
||||
add: add,
|
||||
update: update,
|
||||
inventories: inventories,
|
||||
getInventory: getInventory
|
||||
};
|
||||
|
||||
return svc;
|
||||
|
||||
function loadInventories() {
|
||||
$http.post('/Inventory/All')
|
||||
.success(function(data) {
|
||||
inventories.addRange(data);
|
||||
});
|
||||
}
|
||||
|
||||
function add(inventory) {
|
||||
return $http.post('/Inventory/Add', inventory)
|
||||
.success(function(inventory) {
|
||||
inventories.unshift(inventory);
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user