public JsonResult AddMessage(int otherUserId, string message) { Int64 newMsgId; User currentUser = GetProperty(SessionVariableNames.Current_User) as User; try { newMsgId = DALayer.AddMessage(currentUser.UserId, otherUserId, message); } catch (Exception ex) { return(Json(new { success = false, error = ex.Message }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = true, message = new Message { Date = DateTime.Now.ToShortDateString(), FromUserId = currentUser.UserId, ToUserId = otherUserId, MessageId = newMsgId, Time = DateTime.Now.ToShortTimeString(), Timestamp = DateTime.Now, Value = message } }, JsonRequestBehavior.AllowGet)); }