This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Notification.cshtml
54 lines (48 loc) · 2.37 KB
/
Notification.cshtml
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
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
See LICENSE in the source repository root for complete license information. -->
@model GraphWebhooks.Models.MessageViewModel
@{
ViewBag.Title = "Notification";
string CurrentUser = ViewBag.CurrentUserId;
}
@section Scripts {
<script src="https://ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.2.1.min.js"></script>
<script>
var connection = $.hubConnection();
var hub = connection.createHubProxy("NotificationHub");
hub.on("showNotification", function (messages) {
$.each(messages, function (index, current) { // Iterate through the message collection
if (current.SubscribedUser === '@CurrentUser'.toString()) { // Don't show messages for different users
var card = $("<div class=\"card\"></div>");
var cardBody = $("<div class=\"card-body\"></div>").appendTo(card);
$("<h5 class=\"\"></h5>").text("Message created").appendTo(cardBody);
var table = $("<table class=\"table table-sm\"></table>");
var message = current.Message;
for (prop in message) { // Iterate through message properties
var property = message[prop];
var row = $("<tr></tr>");
$("<th scope=\"row\"></th>").text(prop).appendTo(row);
var valueCol = $("<td></td>").appendTo(row);
$("<code></code>").text(property).appendTo(valueCol);
table.append(row);
}
cardBody.append(table);
$("#message").append(card);
$("#message").append("<br />");
}
});
});
connection.start();
</script>
}
<h2>Messages</h2>
<p>You'll get a notification when your user receives an email. The messages display below.</p>
<p><b>Note:</b> It may take several seconds for the page to update after the user receives a message.</p>
<br />
<div id="message"></div>
<div>
@using (Html.BeginForm("DeleteSubscription", "Subscription"))
{
<button type="submit" class="btn btn-primary">Delete subscription and sign out</button>
}
</div>