我想在ApplyLeave表更改时发送通知.Snenerio就像...... 当用户申请休假时,经理将收到“有人申请休假”的通知。我正在努力解决如何实现这一点。我先使用代码和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 request保存数据。在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>
答案 0 :(得分:1)
您是否看到了聊天教程,您可以在此处应用相同的逻辑。 here is the tutorial
我认为你能做的是,
//send the user name to the server to broadcast to the connected client.
notification.send(user_name_whois_applying, some_msg);
在经理看来,
//connect to the same hub and call the client method.
$(function () {
var notification = $.connection.notificationHub; ;
notification.addNewMessageToPage= onAddMessage;
$.connection.hub.start();
});
function onAddMessage(message) {
// Add the message to somewhere
$('#messages').append( message);
}
我认为这至少应该让你开始:)