Created
November 4, 2017 18:26
-
-
Save CodingTricksHub/09ca374dca50fe896d0caa046ef3d426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('phoneBookApp',[]).controller('CrudCtrl',['$scope','crudService',function($scope,crudService) { | |
$scope.createVM = {} | |
$scope.updateVM = {} | |
$scope.showAlert = false; | |
$scope.loadTableData = function(){ | |
crudService.serviceCall("GET","","").then(function(response) | |
{ | |
if(response.data.length < 1) | |
{ | |
$scope.showAlert = true; | |
$scope.alertName = "Note!" | |
$scope.alertMessage = "These Is No Record To Show." | |
} | |
$scope.phoneBookData =response.data; | |
}); | |
} | |
$scope.addPhoneNumber = function (isValid) | |
{ | |
if(isValid) | |
{ | |
$scope.addPhoneNumberForm.$setPristine(); | |
crudService.serviceCall("POST","",$scope.createVM).then(function(response) | |
{ | |
$scope.showAlert = true; | |
$scope.alertName = "Success!" | |
$scope.alertMessage = "Phone Number Is Created Successfully." | |
$scope.createVM = {}; | |
$scope.loadTableData(); | |
}); | |
} | |
} | |
$scope.openUpdatePhoneNumberModal = function (Id) | |
{ | |
crudService.serviceCall("GET",Id,"").then(function(response) | |
{ | |
$scope.updateVM =response.data; | |
}); | |
} | |
$scope.updatePhoneNumber = function (Id) | |
{ | |
crudService.serviceCall("PUT",Id,$scope.updateVM).then(function(response) | |
{ | |
$scope.showAlert = true; | |
$scope.alertName = "Success!" | |
$scope.alertMessage = "Phone Number Is Updated Successfully." | |
$scope.loadTableData(); | |
}); | |
} | |
$scope.openDeletePhoneNumberModal = function (Id) | |
{ | |
$scope.recordIdToDelete = Id; | |
} | |
$scope.deletePhoneNumber = function (Id) | |
{ | |
crudService.serviceCall("Delete",Id,"").then(function(response) | |
{ | |
$scope.showAlert = true; | |
$scope.alertName = "Success!" | |
$scope.alertMessage = "Phone Number Is Deleted Successfully." | |
$scope.loadTableData(); | |
}); | |
} | |
$scope.loadTableData(); | |
}]) | |
.service('crudService', ['$http', function ($http) { | |
return { | |
serviceCall: function(method,parameter,data) { | |
return $http({ | |
method: method, | |
url: 'http://localhost:11549/api/Directories/'+parameter, | |
data: data | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment