public JsonResult sendmessage([FromBody] sendmessage message, string sessionid) { try { if (!string.IsNullOrEmpty(sessionid) && message != null) { Patient lpatient = IPatient.GetPatientBySessionID(sessionid); User luser = lIUserRepository.getUser(message.message.UserId); if (lpatient != null) { if (luser != null) { if (((message.message.UserType == ConstantsVar.PatientAdministrator && lpatient.Paid == message.message.UserId) || (message.message.UserType == ConstantsVar.Therapist && lpatient.Therapistid == message.message.UserId) || (message.message.UserType == ConstantsVar.Provider && lpatient.ProviderId == message.message.UserId) || message.message.UserType == ConstantsVar.Support)) { DateTime mdatetime = Convert.ToDateTime(Utilities.ConverTimetoServerTimeZone(Convert.ToDateTime(message.message.Datetime), message.timezoneOffset)); Messages lmessage = MessageExtension.MessageViewToMessage(message.message); lmessage.PatientId = lpatient.PatientLoginId; lmessage.Datetime = mdatetime; int res = lIMessageRepository.InsertMessage(lmessage); if (res > 0) { string content = "Patient has sent a message.<br><a href='" + ConfigVars.NewInstance.url + "?ruserid=" + Utilities.EncryptText(luser.UserId) + "&rtype=" + Utilities.EncryptText(luser.Type.ToString()) + "&rpage=" + Utilities.EncryptText("meg") + "'> Click to view</a>"; Smtp.SendGridEmail(luser.Email, "Messages", content); return(Json(new { Status = (int)HttpStatusCode.OK, result = "success", MessageHeaderID = lmessage.MsgHeaderId })); } else { return(Json(new { Status = (int)HttpStatusCode.OK, result = "not inserted" })); } } else { return(Json(new { Status = (int)HttpStatusCode.Forbidden, result = "patient and user is not mapping", TimeZone = DateTime.UtcNow.ToString("s") })); } } else { return(Json(new { Status = (int)HttpStatusCode.Forbidden, result = "user is not configured", TimeZone = DateTime.UtcNow.ToString("s") })); } } else { return(Json(new { Status = (int)HttpStatusCode.Forbidden, result = "patient is not configured", TimeZone = DateTime.UtcNow.ToString("s") })); } } else { return(Json(new { Status = (int)HttpStatusCode.Forbidden, result = "input is not valid", TimeZone = DateTime.UtcNow.ToString("s") })); } } catch (Exception ex) { logger.LogDebug("Get Rx Error: " + ex); return(Json(new { Status = (int)HttpStatusCode.InternalServerError, result = "getting messages failed" })); } }
public JsonResult SendMessage(string id = "", string message = "") { User luser1 = lIUserRepository.getUser(HttpContext.Session.GetString("UserId")); User luser = lIUserRepository.getUser(id); JsonResult lJson = null; try { if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(message)) { if (luser1 != null && (luser.Type == 2 || luser.Type == 3)) { Messages lmessages1 = new Messages(); lmessages1.PatientId = luser1.UserId; lmessages1.BodyText = message; lmessages1.UserId = luser.UserId; lmessages1.UserType = luser.Type; lmessages1.UserName = luser.Name; lmessages1.SentReceivedFlag = 0; lmessages1.ReadStatus = 0; lmessages1.Datetime = DateTime.Now; int res = lIMessageRepository.InsertMessage(lmessages1); if (res > 0) { lmessages1.Datetime = Convert.ToDateTime(Utilities.ConverTimetoBrowserTimeZone(lmessages1.Datetime, DateTime.Now.ToString())); JsonSerializerSettings lsetting = new JsonSerializerSettings(); lsetting.ContractResolver = new CamelCasePropertyNamesContractResolver(); lsetting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; lJson = Json(new { result = "success", message = lmessages1 }, lsetting); return(lJson); } } } } catch (Exception ex) { return(Json("")); } return(Json("")); }