ApplyLeave テーブルが変更されたときに通知を送信したい.シナリオは次のようなものです...ユーザーが休暇を申請すると、マネージャーは「誰かが休暇を申請しました」という通知を受け取ります.私はこれを達成する方法に苦労しています.私はコードを最初に使用し、SignalR を使用して通知を送信します。JavaScript が苦手です。よろしくお願いします。
私の ApplyLeave クラス
public class ApplyLeave
{
public long? EmployeeId { get; set; }
public long? EmployeeLeaveTypesId { get; set; }
public bool Approved { get; set; }
public bool ViewedByManager { get; set; }
public string ManagerRemark { get; set; }
}
私の通知クラス
public class NotificationHub:Hub
{
public void Send(string name, string message)
{
// Call the addNewMessageToPage method to update clients.
Clients.All.addNewMessageToPage(name, message);
}
}
ビューには、id="notify" というボタンがあります。ボタン ai をクリックすると、ajax 要求でデータが保存されます。ajax の成功イベントで、マネージャーに通知を送信する必要があります...これをする
<script type="text/javascript">
$(document).ready(function ()
{
$('#notify').click(function () {
var params = {
"ViewByManager": $('#viewbymanager').val(),
"ManagerRemark": $('#managerremark').val()
};
var dataToPost = JSON.stringify(params);
$.ajax({
type: "POST",
url: "/ApplyLeave/Apply",
contentType: "application/json; charset=utf-8",
data: dataToPost,
dataType: "json",
success: function (data, textStatus){
var notification = $.connection.notificationHub;
// send notification to the manager
},
});
});
});
</script>