public static bool saveClaimDoctor_ext(string _attr_name, string _dname, string _value, long doc_id = 0) { // 01/04/2018: used by Doctor signup/login (HS-67) DateTime dt = DateTime.UtcNow; SV_db1Entities dbEntity = new SV_db1Entities(); try { var d_ext = dbEntity.DOCTOR_ext.Where(a => a.attr_name == _attr_name && a.rel_DOCTOR_id == doc_id).FirstOrDefault(); if (d_ext == null) // add attr if does not exist yet { d_ext = new DOCTOR_ext(); d_ext.rel_DOCTOR_id = doc_id; d_ext.attr_name = _attr_name; d_ext.dname = _dname; d_ext.value = _value; d_ext.dt_create = dt; d_ext.create_by__USER_id = 0; dbEntity.DOCTOR_ext.Add(d_ext); dbEntity.SaveChanges(); } else // update the record if attr already exist { //DOCTOR_ext d_ext = new DOCTOR_ext(); //var d_ext = dbEntity.DOCTOR_ext.Where(a => a.attr_name == _attr_name && a.rel_DOCTOR_id == doc_id).FirstOrDefault(); d_ext.attr_name = _attr_name; d_ext.dname = _dname; d_ext.value = _value; d_ext.dt_update = dt; d_ext.update_by__USER_id = 0; dbEntity.Entry(d_ext).State = System.Data.Entity.EntityState.Modified; dbEntity.SaveChanges(); } } catch (Exception ex) { } return(true); }
public async Task <IHttpActionResult> UpdateRating() { string root = HttpContext.Current.Server.MapPath("~/Temp"); var provider = new MultipartFormDataStreamProvider(root); long user_id = 0, patient_id = 0; int rate = 0; DateTime dtNow = DateTime.Now; try { await Request.Content.ReadAsMultipartAsync(provider); foreach (var key in provider.FormData.AllKeys) { foreach (var val in provider.FormData.GetValues(key)) { // user_id, patient_id, rate bool bTemp = false; switch (key) { case "user_id": IsRequired(key, val, 1); bTemp = long.TryParse(val, out user_id); break; case "patient_id": IsRequired(key, val, 1); bTemp = long.TryParse(val, out patient_id); break; case "rate": IsRequired(key, val, 1); bTemp = int.TryParse(val, out rate); break; default: return(Json(new { message = "Invalid parameter name: " + key, success = false })); } } } var pat_ext = db.SOUL_ext.Where(a => a.rel_SOUL_id == patient_id && a.attr_name == "rating"); if (pat_ext.Count() > 0) { foreach (var i in pat_ext) { if (i.attr_name == "rating") { i.value = rate.ToString(); i.update_by__USER_id = user_id; i.dt_update = dtNow; db.Entry(i).State = System.Data.Entity.EntityState.Modified; } } db.SaveChanges(); } else { return(Json(new { data = new string[] { }, message = "No matching record found." })); } //DOCTOR_ext doc_ext = new DOCTOR_ext() //{ // rel_DOCTOR_id = doctor_id, // attr_name = "rating", // dname = "Rating", // value = rate.ToString(), // rel_ref_datatype_id = 3 //}; //db.DOCTOR_ext.Add(doc_ext); return(Json(new { data = new string[] { }, message = "Doctor rating saved successfully.", success = true })); } catch (Exception ex) { return(Json(new { data = new string[] { }, message = ex.Message, success = false })); } }
public async Task <IHttpActionResult> putappointmenttype() { string msg = ""; string root = HttpContext.Current.Server.MapPath("~/Temp"); var provider = new MultipartFormDataStreamProvider(root); string appointment_type_id = ""; try { string display_name = ""; string user_id = ""; await Request.Content.ReadAsMultipartAsync(provider); foreach (var key in provider.FormData.AllKeys) { foreach (var val in provider.FormData.GetValues(key)) { switch (key) { case "appointment_type_id": IsRequired(key, val, 1); appointment_type_id = val; break; case "display_name": IsRequired(key, val, 1); display_name = val; break; case "user_id": user_id = val; break; default: msg = "Object reference not set to an instance of an object. Invalid parameter name: " + key; return(Json(new { data = new string[] { }, message = msg, success = false })); } } } IsRequired("display_name", display_name, 1); if (haserror) { return(Json(new { data = new string[] { }, message = errmsg, success = false })); } long nApp_type = 0; bool bApp_type = long.TryParse(appointment_type_id, out nApp_type); var app_type = dbEntity.ref_APPOINTMENT_type.Find(nApp_type); if (app_type != null) { app_type.dname = display_name; dbEntity.Entry(app_type).State = System.Data.Entity.EntityState.Modified; dbEntity.SaveChanges(); } //var ret1 = JsonConvert.SerializeObject(appointment); //var json1 = Newtonsoft.Json.Linq.JArray.Parse(ret1); //msg = appointment.Count() + " Record(s) found."; return(Json(new { data = new string[] { }, message = msg, success = true })); } catch (Exception ex) { return(Json(new { data = new string[] { }, message = ex.Message, success = false })); } }
public IHttpActionResult updateAppointmentSched(long user_id = 0, string doctor_id = "", string appointment_id = "", string review = "", int rate = 0) { string root = HttpContext.Current.Server.MapPath("~/Temp"); var provider = new MultipartFormDataStreamProvider(root); //long user_id = 0, doctor_id = 0; //string review = "", appointment_id = ""; //int rate = 0; DateTime dtNow = DateTime.Now; try { //await Request.Content.ReadAsMultipartAsync(provider); //foreach (var key in provider.FormData.AllKeys) //{ // foreach (var val in provider.FormData.GetValues(key)) // { // // user_id, patient_id, rate // bool bTemp = false; // switch (key) // { // case "user_id": // IsRequired(key, val, 1); // bTemp = long.TryParse(val, out user_id); // break; // case "doctor_id": // //IsRequired(key, val, 1); // bTemp = long.TryParse(val, out doctor_id); // break; // case "appointment_id": // IsRequired(key, val, 1); // appointment_id = val; // break; // case "review": // IsRequired(key, val, 1); // //bTemp = int.TryParse(val, out rate); // review = val; // break; // case "rate": // IsRequired(key, val, 1); // bTemp = int.TryParse(val, out rate); // break; // default: // return Json(new { message = "Invalid parameter name: " + key, success = false }); // } // } //} // IsRequired("doctor_id", doctor_id.ToString(), 3); IsRequired("appointment_id", appointment_id, 3); IsRequired("rate", rate.ToString(), 3); IsRequired("review", review.ToString(), 2); if (haserror) { return(Json(new { data = new string[] { }, message = errmsg, success = false })); } //var doc_ext = db.APPOINTMENT_ext.Where(a => a.rel_DOCTOR_id == doctor_id && a.attr_name == "rating"); long appt_id_new = 0; bool bAppt = long.TryParse(appointment_id, out appt_id_new); var appt_ext = db.APPOINTMENT_ext.Where(a => a.rel_APPOINTMENT_id == appt_id_new); if (appt_ext.Count() > 0) { bool hasRate = false, hasReview = false; foreach (var i in appt_ext) { if (i.attr_name == "doctor_rating") { i.value = rate.ToString(); i.update_by__USER_id = user_id; i.dt_update = dtNow; db.Entry(i).State = System.Data.Entity.EntityState.Modified; hasRate = true; } if (i.attr_name == "doctor_review") { i.value = review.ToString(); i.update_by__USER_id = user_id; i.dt_update = dtNow; db.Entry(i).State = System.Data.Entity.EntityState.Modified; hasReview = true; } } //long appt_id = appt_ext.FirstOrDefault().id; if (!string.IsNullOrEmpty(rate.ToString()) && !hasRate) { APPOINTMENT_ext doc_ext = new APPOINTMENT_ext() { rel_APPOINTMENT_id = appt_id_new, attr_name = "doctor_rating", dname = "Doctor Rating", value = rate.ToString(), rel_ref_datatype_id = 3, create_by__USER_id = user_id, dt_create = dtNow }; db.APPOINTMENT_ext.Add(doc_ext); } if (!string.IsNullOrEmpty(review) && !hasReview) { APPOINTMENT_ext doc_rev = new APPOINTMENT_ext() { rel_APPOINTMENT_id = appt_id_new, attr_name = "doctor_review", dname = "Doctor Review", value = review.ToString(), rel_ref_datatype_id = 3, create_by__USER_id = user_id, dt_create = dtNow }; db.APPOINTMENT_ext.Add(doc_rev); } db.SaveChanges(); } else { return(Json(new { data = "", message = "No matching record found.", success = false })); } //DOCTOR_ext doc_ext = new DOCTOR_ext() //{ // rel_DOCTOR_id = doctor_id, // attr_name = "rating", // dname = "Rating", // value = rate.ToString(), // rel_ref_datatype_id = 3 //}; //db.DOCTOR_ext.Add(doc_ext); return(Json(new { data = new string[] { }, message = "Doctor rating saved successfully.", success = true })); } catch (Exception ex) { return(Json(new { data = new string[] { }, message = ex.Message, success = false })); } }
public async Task <IHttpActionResult> putNotification() { string root = HttpContext.Current.Server.MapPath("~/Temp"); var provider = new MultipartFormDataStreamProvider(root); string msg, user_id = null, notification_id = null, text = null, link = null, is_unread = null; try { #region "params" await Request.Content.ReadAsMultipartAsync(provider); foreach (var key in provider.FormData.AllKeys) { foreach (var val in provider.FormData.GetValues(key)) { switch (key) { case "user_id": isRequired(key, val, 1); user_id = val; break; //case "patient_id": // patient_id = val; // break; case "notification_id": notification_id = val; isRequired(key, val, 1); break; case "text": text = val; break; case "link": link = val; break; case "is_unread": is_unread = val; break; default: msg = "Object reference not set to an instance of an object. Invalid parameter name: " + key; return(Json(new { data = new string[] { }, message = msg, success = false })); } } } isRequired("user_id", user_id, 1); isRequired("notification_id", notification_id, 1); if (hasError) { return(Json(new { data = new string[] { }, message = errmsg, success = false })); } // check user info long user_id_new = 0; bool isValidUser = long.TryParse(user_id, out user_id_new); if (!isValidUser) { return(Json(new { data = new string[] { }, message = "Invalid user_id value.", success = false })); } var _user = db.USERs.Find(user_id_new); if (_user == null) { return(Json(new { data = new string[] { }, message = "Invalid user_id value.", success = false })); } // check notif_id info long notif_id_new = 0; bool isValidPatient = long.TryParse(notification_id, out notif_id_new); if (!isValidPatient) { return(Json(new { data = new string[] { }, message = "Invalid notification_id value.", success = false })); } var notif = db.notifications.Find(notif_id_new); if (notif == null) { return(Json(new { data = new string[] { }, message = "Invalid notification_id value.", success = false })); } // check is_read value if (is_unread.ToLower() != "false" || is_unread.ToLower() != "true") { return(Json(new { data = new string[] { }, message = "Invalid patient_id value.", success = false })); } #endregion if (!string.IsNullOrEmpty(text)) { notif.text = text; } if (!string.IsNullOrEmpty(link)) { notif.link = link; } if (!string.IsNullOrEmpty(is_unread)) { notif.is_unread = is_unread.ToLower() == "true" ? true : false; } notif.update_by__USER_id = user_id_new; notif.dt_update = dt; //notification noti = new notification //{ // rel_USER_id = user_id_new, // SOUL_id = patient_id_new, // text = text, // link = link, // is_unread = is_unread.ToLower() == "true" ? true : false, //}; db.Entry(notif).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Json(new { data = new string[] { }, message = "Notification successfully saved.", success = true })); } catch (Exception ex) { return(Json(new { data = new string[] { }, message = ex.Message, success = false })); } }