public async Task <HttpResponseMessage> addPatientFamilyHX(PatientFamilyHX_Custom model) { PatientFamilyHX phx = new PatientFamilyHX(); try { if (model.name == null || model.name == "") { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid familyHX." }); return(response); } if (model.patientID == null || model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient id." }); return(response); } phx = db.PatientFamilyHXes.Where(p => p.name.Trim() == model.name.Trim() && p.patientID == model.patientID).FirstOrDefault(); if (phx != null) { phx.relationship = model.relationship; phx.md = System.DateTime.Now; phx.mb = phx.patientID.ToString(); phx.active = true; db.Entry(phx).State = EntityState.Modified; await db.SaveChangesAsync(); response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = phx.fhxid, message = "" }); return(response); } if (phx == null) { phx = new PatientFamilyHX(); phx.active = true; phx.name = model.name; phx.relationship = model.relationship; phx.patientID = model.patientID; phx.cd = System.DateTime.Now; phx.cb = model.patientID.ToString(); db.PatientFamilyHXes.Add(phx); await db.SaveChangesAsync(); } } catch (Exception ex) { return(ThrowError(ex, "AddPatientFamilyHX in PatientFamilyHXController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = phx.fhxid, message = "" }); return(response); }
public async Task <HttpResponseMessage> UpdatePatientFamilyHX(UpdateFamilyHX model) { PatientFamilyHX pls = new PatientFamilyHX(); try { if (model.patientID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid patient ID." }); return(response); } pls = db.PatientFamilyHXes.Where(all => all.fhxid == model.patientfamilyHXID).FirstOrDefault(); if (pls != null) { pls.relationship = model.relationship; pls.md = System.DateTime.Now; pls.mb = model.patientID.ToString(); db.Entry(pls).State = EntityState.Modified; await db.SaveChangesAsync(); } else { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "PatientLifeStyle not found." }); return(response); } } catch (Exception ex) { return(ThrowError(ex, "EditPatientLifeStyle in PatientLifeStyleController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = model.patientfamilyHXID, message = "" }); return(response); }
public async Task <HttpResponseMessage> RemovePatientFamilyHX(long fhxID) { try { if (fhxID == 0) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid FamilyHX ID." }); return(response); } PatientFamilyHX pfhx = await db.PatientFamilyHXes.FindAsync(fhxID); if (pfhx == null) { response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "FamilyHX not found." }); return(response); } else { pfhx.active = false;//Delete Operation changed pfhx.mb = pfhx.patientID.ToString(); pfhx.md = System.DateTime.Now; db.Entry(pfhx).State = EntityState.Modified; await db.SaveChangesAsync(); } } catch (Exception ex) { return(ThrowError(ex, "DeletePatientFamilyHX in PatientFamilyHXController.")); } response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel { ID = fhxID, message = "" }); return(response); }