public JsonResult AddUpdateSurgeries(long surgeryID, PatientSurgery_Custom surgery) { try { if (surgery.bodyPart == null || surgery.bodyPart == "")//!Regex.IsMatch(surgery.bodyPart, @"^[a-zA-Z\s]+$")) { ApiResultModel apiresult = new ApiResultModel(); apiresult.message = "Provide surgery name."; return(Json(new { Success = true, ApiResultModel = apiresult })); } SurgeriesRepository objRepo = new SurgeriesRepository(); if (surgeryID == 0) { ApiResultModel apiresult = objRepo.AddPatientSurgery(surgery); return(Json(new { Success = true, ApiResultModel = apiresult })); } else { ApiResultModel apiresult = objRepo.EditPatientSurgery(surgeryID, surgery); return(Json(new { Success = true, ApiResultModel = apiresult })); } } catch (Exception ex) { return(Json(new { Message = ex.Message })); } }
public async Task <HttpResponseMessage> AddPatientSugery(PatientSurgery_Custom model) { PatientSurgery psurgery = new PatientSurgery(); try { if (model.bodyPart == null || model.bodyPart == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid surgery name." }); return(response); } if (model.patientID == null || model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient id." }); return(response); } psurgery = db.PatientSurgeries.Where(p => p.bodyPart.Trim() == model.bodyPart.Trim() && p.patientID == model.patientID && p.active == true).FirstOrDefault(); if (psurgery != null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Surgery already exists." }); response.ReasonPhrase = "Surgery already exists."; return(response); } if (psurgery == null) { psurgery = new PatientSurgery(); psurgery.active = true; psurgery.bodyPart = model.bodyPart; psurgery.patientID = model.patientID; psurgery.cd = System.DateTime.Now; psurgery.reportedDate = System.DateTime.Now; psurgery.cb = model.patientID.ToString(); db.PatientSurgeries.Add(psurgery); await db.SaveChangesAsync(); } } catch (Exception ex) { return(ThrowError(ex, "AddPatientSurgery in PatientSurgeriesController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = psurgery.surgeryID, message = "" }); return(response); }
public async Task <HttpResponseMessage> EditPatientSugery(long surgeryID, PatientSurgery_Custom model) { PatientSurgery psurgery = new PatientSurgery(); try { if (model.bodyPart == null || model.bodyPart == "" || !Regex.IsMatch(model.bodyPart.Trim(), "^[0-9a-zA-Z ]+$")) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid surgery. Only letters and numbers are allowed." }); return(response); } if (model.patientID == null || model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient id." }); return(response); } psurgery = db.PatientSurgeries.Where(all => all.bodyPart.Trim() == model.bodyPart.Trim() && all.surgeryID != surgeryID && all.active == true).FirstOrDefault(); if (psurgery != null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Surgery already exists." }); response.ReasonPhrase = "Surgery already exists."; return(response); } psurgery = db.PatientSurgeries.Where(m => m.surgeryID == surgeryID).FirstOrDefault(); if (psurgery == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Surgery not found." }); return(response); } psurgery.bodyPart = model.bodyPart; psurgery.md = System.DateTime.Now; psurgery.mb = psurgery.patientID.ToString(); db.Entry(psurgery).State = EntityState.Modified; await db.SaveChangesAsync(); } catch (Exception ex) { return(ThrowError(ex, "EditPatientSurgery in PatientSurgeriesController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = surgeryID, message = "" }); return(response); }
public ApiResultModel EditPatientSurgery(long id, PatientSurgery_Custom condition) { try { var strContent = JsonConvert.SerializeObject(condition); var response = ApiConsumerHelper.PostData("api/editPatientSurgery?surgeryID=" + id, strContent); var result = JsonConvert.DeserializeObject <ApiResultModel>(response); return(result); } catch (Exception ex) { throw ex; } }