public async Task <JsonResult> Insert()
        {
            try {
                var id    = Guid.NewGuid();
                var text  = Request.Form["text"];
                var mtype = Guid.Parse(Request.Form["mtype"]);
                var sid   = Request.Form["sid"];
                var rid   = Guid.Parse(Request.Form["rid"]);
                var api   = Guid.Parse(Request.Form["api"]);
                if (MessagingConversationService.Insert(id, text, mtype, sid, rid, DateTime.Now))
                {
                    //add notification to users that this user sent a message
                    //do not include the uid that sent the message
                    var receipents = MessagingRoomParticipantService.GetByRoomIDExceptUID(rid, sid);
                    var nid        = Guid.NewGuid();
                    NotificationService.Insert(nid, text, api, "New Message");
                    foreach (var r in receipents)
                    {
                        var nrID = Guid.NewGuid();
                        NotificationService.InsertNR(nrID, nid, r.UserID, api);
                        //invoke signal r that there is a new message notification for the users
                        //nrID=id for notificationReceipent so that if its confirmed received this id will be passed back to the
                        //server to remove the notificationreceipent

                        var textToSend = this.IdentifyMessageNotification(mtype.ToString(), text);
                        NotificationManagerHub.SendNotification(nrID.ToString(), api.ToString(), r.UserID, "New Message", textToSend);
                        MessagingAppHub.SendNotification(id.ToString(), api.ToString(), rid.ToString());
                    }
                    return(Success(id.ToString()));
                }
                return(Failed(MessageUtility.ServerError()));
            } catch { return(Failed(MessageUtility.ServerError())); }
        }
 public static bool Remove(Guid id)
 {
     try {
         using (var context = new UploadersContext()) {
             var query = (from i in context.MessagingRoomParticipantsDB where i.ID == id select i).FirstOrDefault();
             //invoke signalR hub that someone is leaving the room
             MessagingAppHub.LeaveRoom(query.RoomID.ToString(), query.UserID, query.API.ToString());
             context.MessagingRoomParticipantsDB.Remove(query);
             context.SaveChanges();
             return(true);
         }
     } catch { return(false); }
 }
示例#3
0
 //receiverID, MessagingConversationID
 //receiver=userID find its signalRConnection
 //mcid=messageConversationID
 public async Task <JsonResult> NewMessageSent()
 {
     try{
         var rmid = Guid.Parse(Request.Form["rmid"]);
         var mcid = Guid.Parse(Request.Form["mcid"]);
         var rid  = Guid.Parse(Request.Form["rid"]);
         var aid  = Guid.Parse(Request.Form["aid"]);
         var sid  = SignalRDataService.GetByOIDAPI(rid, aid);
         MessagingAppHub.NewMessage(rmid.ToString(), mcid.ToString(), aid.ToString(), sid.SignalRID.ToString());
         return(Success(sid.SignalRID.ToString()));
     }
     catch { return(Failed(MessageUtilityService.ServerError())); }
 }