2013-10-05 38 views
0

我想在ApplyLeave表格更改時發送通知.Scenerio類似於... 當用戶申請休假時,管理員將收到「有人申請休假」的通知。我很掙扎關於如何做到這一點,我先使用代碼,然後使用SignalR發送通知。我不擅長javascript.Thanks提前。更改表格時的通知

我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 = 「通知」。上點擊AI正與阿賈克斯reques保存數據的按鈕。在阿賈克斯成功事件我需要發送通知給經理....我真的不知道如何做到這一點

<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); 
} 

我認爲這至少應該讓你走了:)