Esempio n. 1
0
        public string Post(HttpRequestMessage request)
        {
            string response = "";
            //string s = Request.Content.ReadAsStringAsync().Result;

            var             jsonString = request.Content.ReadAsStringAsync().Result;
            MessageDetails  msgDetails = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageDetails>(jsonString);
            UserDetail      userDetail = new UserDetail();
            ResponseMessage resp       = new ResponseMessage();

            try
            {
                if (msgDetails != null || msgDetails.Id != null)
                {
                    if (GeneralActions.GetEncryptData(msgDetails.Id, ref userDetail, ref resp))
                    {
                        var context = GlobalHost.ConnectionManager.GetHubContext <IMIchatHub>();
                        // context.Clients.All.Send("Admin", "stop the chat");
                        context.Clients.Group(userDetail.teamId.ToString()).chatMessage(msgDetails.Message);
                        resp.code = 200;
                        resp.desc = "Success";
                    }
                }
                else
                {
                    resp.code = 405;
                    resp.desc = "Invalid Data";
                }
            }
            catch
            {
                resp.code = 500;
                resp.desc = "Error";
            }
            finally
            {
                response = Newtonsoft.Json.JsonConvert.SerializeObject(resp);
            }
            return(response);
        }
Esempio n. 2
0
        public string PostMessage([FromBody] MessageDetails msgDetails)
        {
            string          response   = "";
            UserDetail      userDetail = new UserDetail();
            ResponseMessage resp       = new ResponseMessage();

            try
            {
                if (msgDetails != null)
                {
                    if (GeneralActions.GetEncryptData(msgDetails.Id, ref userDetail, ref resp))
                    {
                        var context = GlobalHost.ConnectionManager.GetHubContext <IMIchatHub>();

                        List <UserDetail> toUserList = IMIchatHub.ConnectedUsers.Where(x => x.userId == userDetail.userId).ToList();
                        foreach (var user in toUserList) //if logined into different browsers
                        {
                            context.Clients.Client(user.connectionId).sendPrivateMessage(msgDetails.Message);
                        }
                        resp.code = 200;
                        resp.desc = "Success";
                    }
                }
                else
                {
                    resp.code = 405;
                    resp.desc = "Invalid Data";
                }
            }
            catch
            {
                resp.code = 500;
                resp.desc = "Error";
            }
            finally
            {
                response = Newtonsoft.Json.JsonConvert.SerializeObject(resp);
            }
            return(response);
        }