单击“取消”按钮时,我需要取消已发送的请求。不幸的是,到目前为止,发送的请求还没有被取消。我的用例是,一旦用户单击“取消”按钮,就会出现一个弹出窗口,然后如果用户单击“取消请求”,则应取消“朋友请求”,否则,如果用户单击“不取消请求”,则应保留该朋友请求完整。我正在使用SignalR发送请求
以下是我的相同代码:
Controller.js
$scope.InviteNurse = function (NurseId, Type) {
var NurseFriendId = $("#connect_" + NurseId).attr("NurseFriendId");
alert(Type);
if ($scope.CurrentUser) {
if (Type != 3)
{
var RequestObject = {
NurseId: NurseId,
FNurseId: $scope.CurrentUser.NurseId,
Type: Type,
NurseFriendId: NurseFriendId
}
signalR.InviteNurse(RequestObject);
if (RequestObject) {
RequestObject.InvitedBy = $scope.CurrentUser.NurseId;
RequestObject.NurseId = NurseId;
}
}
//==============================================Updating Local Buttons for ShowAlert========================================//
if(Type == 1)
{
UserService.showAlert('Your Invitation to Connect has been sent', 1);
}
if(Type == 3)
{
$('#confirm').modal('show');
}
if (Type == 2)
{
UserService.showAlert('You have Accepted the Invitation to Connect', 3);
}
}
}
$scope.RequestCancel = function () {
$('#confirm').modal('hide');
UserService.showAlert('You have Cancelled the Invitation to Connect!', 0);
}
$scope.Cancel = function () {
$('#confirm').modal('hide');
UserService.showAlert('You clicked on Do Not Cancel Invite!', 2);
}
$scope.InitType = function (NurseId, Type) {
switch (Type) {
case 0:
$("#cancel_" + NurseId).hide();
$("#connect_" + NurseId).show();
$("#accept_" + NurseId).hide();
$("#reject_" + NurseId).hide();
$("#message_" + NurseId).hide();
break;
case 1:
$("#cancel_" + NurseId).show();
$("#connect_" + NurseId).hide();
$("#accept_" + NurseId).hide();
$("#reject_" + NurseId).hide();
$("#message_" + NurseId).hide();
break;
case 2:
case 3:
$("#cancel_" + NurseId).hide();
$("#connect_" + NurseId).hide();
$("#accept_" + NurseId).hide();
$("#reject_" + NurseId).hide();
$("#message_" + NurseId).show();
break;
case 4:
$("#cancel_" + NurseId).hide();
$("#connect_" + NurseId).hide();
$("#accept_" + NurseId).html('<i class="fa fa-check"></i>').show();
$("#reject_" + NurseId).html('<i class="fa fa-times"></i>').show();
$("#message_" + NurseId).hide();
}
}
以下是 ChatHub.cs的代码:
public void InviteNurse(NurseFriend objNurseFriend)
{
Result res = null;
//if (res.Status == true)
{
var InvitedTo = objConnectedUserList.FirstOrDefault(x =>
(x.NurseId == objNurseFriend.NurseId)
);
switch (objNurseFriend.Type)
{
case "1":
res = objMessagingDAL.InsertFriendRequest(objNurseFriend);
var fromRequestObject = new
{
FNurseId = objNurseFriend.FNurseId,
ToNurseId = objNurseFriend.NurseId,
Type = 1,
NurseFriendId = res.Results
};
var toRequestObject = new
{
//FNurseName = InvitedBy.NurseName,
FNurseId = objNurseFriend.FNurseId,
ToNurseId = objNurseFriend.NurseId,
Type = 4,
NurseFriendId = res.Results
};
if (InvitedTo != null)
{
Clients.Client(InvitedTo.ConnectionId).notifyUser(toRequestObject);
Clients.Client(InvitedTo.ConnectionId).toAcceptRejectRequest(toRequestObject);
}
Clients.Caller.fromAcceptRejectRequest(fromRequestObject);
break;
case "2":
var fromRequestObject1 = new
{
FNurseId = objNurseFriend.FNurseId,
ToNurseId = objNurseFriend.NurseId,
Type = 3
};
var toRequestObject1 = new
{
//FNurseName = InvitedBy.NurseName,
FNurseId = objNurseFriend.FNurseId,
ToNurseId = objNurseFriend.NurseId,
Type = 2
};
objNurseFriend.IsAccepted = true;
res = objMessagingDAL.UpdateFriendRequest(objNurseFriend);
if (InvitedTo != null)
{
Clients.Client(InvitedTo.ConnectionId).notifyUser(toRequestObject1);
Clients.Client(InvitedTo.ConnectionId).toAcceptRejectRequest(toRequestObject1);
}
Clients.Caller.fromAcceptRejectRequest(fromRequestObject1);
break;
case "3":
var fromRequestObject2 = new
{
FNurseId = objNurseFriend.FNurseId,
ToNurseId = objNurseFriend.NurseId,
Type = 0
};
var toRequestObject2 = new
{
//FNurseName = InvitedBy.NurseName,
FNurseId = objNurseFriend.FNurseId,
ToNurseId = objNurseFriend.NurseId,
Type = 0
};
res = objMessagingDAL.DeleteFriendRequest(objNurseFriend);
if (InvitedTo != null)
{
Clients.Client(InvitedTo.ConnectionId).toAcceptRejectRequest(toRequestObject2);
}
Clients.Caller.fromAcceptRejectRequest(fromRequestObject2);
break;
}
}
}
这就是我从 HTML:
调用代码的方式<div class="peoplemain-container" ng-controller="connectCtrl">
@foreach (var item in Model)
{
<div class="people_container">
<div class="connect_profile"><img src="@(item.ProfileUrl== "" ?"/image/placeholder.jpg" : @item.ProfileUrl)" title="@item.Title @item.FirstName @item.LastName" /></div>
<div class="clear"></div>
<div class="job_box">
<p><b>@item.Title @item.FirstName @item.LastName</b></p>
<p><span>@item.Profession</span></p>
</div>
<div class="job_box_btn">
<button class="details_btn">
@Html.ActionLink("View Nurse", "NurseView", "Nurse", new { NurseId = item.NurseId }, new { @class = "" })
</button>
<button class="details_btn">
<a style="display:@(item.Status==0? "block": "none")" id="connect_@item.NurseId" NurseFriendId="@item.NurseFriendId" ng-click="InviteNurse(@item.NurseId, 1)">Connect</a>
<a style="display:@(item.Status==1? "block": "none")" id="cancel_@item.NurseId" NurseFriendId="@item.NurseFriendId" ng-click="InviteNurse(@item.NurseId,3)">Cancel</a>
<a style="display:@(item.Status==2 || item.Status==3? "block": "none")" id="message_@item.NurseId" NurseFriendId="@item.NurseFriendId" href="/Nurse/GetInbox?FromNurseId=@NurseOneStop.WebSite.Models.ApplicationSession.CurrentUser.NurseId&ToNurseId=@item.NurseId">Message</a>
<a style="display:@(item.Status==4? "block": "none")" id="accept_@item.NurseId" NurseFriendId="@item.NurseFriendId" ng-click="InviteNurse(@item.NurseId,2);"> <i class="fa fa-check"></i></a>
<a style="display:@(item.Status==4? "block": "none")" id="reject_@item.NurseId" NurseFriendId="@item.NurseFriendId" ng-click="InviteNurse(@item.NurseId,3);"><i class="fa fa-times"></i></a>
</button>
</div>
</div>
}
</style>
<!--Confirm Modal -->
<div id="confirm" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Cancel the Invitation to Connect</h4>
</div>
<div class="modal-body">
<h2>Are you sure you want to Cancel the Invitation to Connect</h2>
<input type="button" class="btn" ng-click="RequestCancel()" value="CANCEL INVITE">
<input type="button" class="btn" ng-click="Cancel()" value="DO NOT CANCEL INVITE">
</div>
</div>
</div>
</div>