-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIndex.cshtml
More file actions
93 lines (89 loc) · 2.55 KB
/
Index.cshtml
File metadata and controls
93 lines (89 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<div id="body">
<ul id="users"></ul>
<form id="saveUserForm" method="post">
<h3>Add a New User</h3>
<p>
<label for="User Name">User Name:</label>
<input type="text" name="UserName" />
</p>
<p>
<label for="House Name">House Name:</label>
<input type="text" name="HouseName" />
</p>
<p>
<label for="User Password">Password:</label>
<input type="text" name="Password" />
</p>
<input type="button" id="register" value="Register" />
</form>
<form id="deleteUserForm" method="delete">
<h3>Delete a User</h3>
<p>
<label for="User Name">User Name:</label>
<input type="text" name="UserName" />
</p>
<p>
<label for="Password">Password:</label>
<input type="text" name="Password" />
</p>
<input type="button" id="delete" value="Delete" />
</form>
</div>
@section scripts{
<script type="text/javascript">
$(function () {
$.ajax({
type: 'GET',
url: 'api/user',
dataType: "json",
success: function (data) {
$(data).each(function (i, item) {
$('#users').append('<li>' + "User: " + item.UserName + " (Password: " + item.Password + ')' + '<ul>' + '<li>'
+ "House: " + item.MyHouses.HouseName + '</li>' + '</ul>' + '</li>');
});
},
error: function () {
alert('error handing here');
}
});
});
$('#register').click(function () {
var datastring = $("#saveUserForm").serialize();
$.ajax({
type: 'POST',
url: 'api/user',
data: datastring,
dataType: "json",
success: function (data) {
$('#users').append('<li>' + "User: " + data.UserName + " (Password: " + data.Password + ')' + '<ul>' + '<li>'
+ "House: " + data.MyHouses.HouseName + '</li>' + '</ul>' + '</li>');
},
error: function () {
alert('error handing here');
}
});
});
$('#delete').click(function () {
var datastring = $("#deleteUserForm").serialize();
$.ajax({
type: 'DELETE',
url: 'api/user',
data: datastring,
dataType:"json",
success: function (data) {
var str = datastring.split("&");
var name = (str[0].split("Name="));
var password = str[1].split("Password=");
var house = str[2].split("HouseName=");
console.log(name[0]);
console.log(password[0]);
console.log(house[0]);
document.getElementById(name[0]).remove();
},
error: function () {
alert('error handling here');
}
});
});
</script>
}