public JsonResult SendMessage(string messages, string FromUser, string ToUser) { chatService = new WebChatService.ChatServiceClient(); var fromUser = chatService.GetUser().FirstOrDefault(x => x.UserName == FromUser.Substring(1, FromUser.Length - 2)); var toUser = chatService.GetUser().FirstOrDefault(x => x.UserName == ToUser); MessageModel message = new MessageModel(); message.From = fromUser; message.To = toUser; message.Text = messages; var result = SendMessage(message); WebChatService.Message sendMessage = new WebChatService.Message(); sendMessage.Text = messages; sendMessage.To = toUser; sendMessage.From = fromUser; sendMessage.SendDate = DateTime.Now; if (result) { return(Json(sendMessage, JsonRequestBehavior.AllowGet)); } else { return(Json(null, JsonRequestBehavior.AllowGet)); } }
bool SendMessage(MessageModel message) { chatService = new WebChatService.ChatServiceClient(); WebChatService.Message wsMessage = new WebChatService.Message(); wsMessage.Text = message.Text; wsMessage.From = message.From; wsMessage.To = message.To; var result = chatService.SendMessage(wsMessage); if (result) { return(true); } else { return(false); } }