我想在 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" 的按钮。单击按钮时,我正在使用 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>