0

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>
4

1 に答える 1

1

チャットのチュートリアルを見ましたか? ここで同じロジックを適用できます。 ここにチュートリアルがあります

あなたにできることは、

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

私はこれが少なくともあなたを始めさせるべきだと思います:)

于 2013-10-05T18:38:06.050 に答える