<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contacts HTML Client</title>
<link href="Content/bootstrap.css" rel="stylesheet" />
<style type="text/css">
body {
margin-top: 60px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Contacts</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav"></ul>
<ul class="nav navbar-nav navbar-right">
<li><a class="btn btn-link" ng-show="userInfo.isAuthenticated" ng-click="logout()">Logout</a></li>
<li><a class="btn btn-link" ng-hide=" userInfo.isAuthenticated" ng-click="login()">Login</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<!-- contacts ui here -->
<table class="table table-striped" ng-app="myApp" ng-controller="contactListCtrl">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="con in contacts">
<td>{{con.Id}}</td>
<td>{{con.Name}}</td>
<td>{{con.EmailAddress}}</td>
<td><button class="btn btn-sm btn-warning" ng-click="delete(con.Id)">Delete</button></td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Create a new Contact</th>
<th colspan="2">API Status: {{status}}</th>
<th><button class="btn btn-sm btn-info" ng-click="refresh()">Refresh</button></th>
</tr>
<tr>
<td><input type="text" placeholder="ID" ng-model="newId" /></td>
<td><input type="text" placeholder="Name" ng-model="newName" /></td>
<td><input type="text" placeholder="Email Address" ng-model="newEmail" /></td>
<td><button class="btn btn-sm btn-success" ng-click="create()">Create</button></td>
</tr>
<tr>
<td colspan="4">API URL: {{baseUrl}}</td>
</tr>
</tfoot>
</table>
</div>
<script src="Scripts/angular.js" type="text/javascript"></script>
<script type="text/javascript">
/* client javascript code here */
angular.module('myApp', []).controller('contactListCtrl', function ($scope, $http) {
//$scope.baseUrl = 'http://{api app name}.azurewebsites.net';
$scope.baseUrl = 'http://localhost:51864';
$scope.refresh = function () {
$scope.status = "Refreshing Contacts...";
$http({
method: 'GET',
url: $scope.baseUrl + '/api/contacts',
headers: {
'Content-Type': 'application/json'
}
}).then(function (results) {
$scope.contacts = results.data;
$scope.status = "Contacts loaded";
}, function (err) {
$scope.status = "Error loading contacts";
});
};
$scope.create = function () {
$scope.status = "Creating a new contact";
$http({
method: 'POST',
url: $scope.baseUrl + '/api/contacts',
headers: {
'Content-Type': 'application/json'
},
data: {
'Id': $scope.newId,
'Name': $scope.newName,
'EmailAddress': $scope.newEmail
}
}).success(function (data) {
$scope.status = "Contact created";
$scope.refresh();
$scope.newId = 0;
$scope.newName = '';
$scope.newEmail = '';
});
};
$scope.delete = function (id) {
$scope.status = "Deleting contact";
$http({
method: 'DELETE',
url: $scope.baseUrl + '/api/contacts/' + id
}).success(function (data) {
$scope.status = "Contact deleted";
$scope.refresh();
});
};
$scope.refresh();
});
</script>
</body>
</html>