public async Task <HttpResponseMessage> EditPatientLifeStyle(PatientLifeStyleModel model)
        {
            PatientLifeStyle pls = new PatientLifeStyle();

            try
            {
                if (model.answer == null || model.answer == "")
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "Invalid answer."
                    });
                    return(response);
                }
                if (model.patientlifestyleID == 0)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "Invalid patient life style ID."
                    });
                    return(response);
                }
                if (model.patientID == 0)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "Invalid patient ID."
                    });
                    return(response);
                }
                pls = db.PatientLifeStyles.Where(all => all.patientlifestyleID == model.patientlifestyleID && all.patientID == model.patientID).FirstOrDefault();
                if (pls != null)
                {
                    pls.answer          = model.answer;
                    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.patientlifestyleID, message = ""
            });
            return(response);
        }
Ejemplo n.º 2
0
 public JsonResult UpdateLifeStyle(PatientLifeStyleModel _objPLS)
 {
     try
     {
         ApiResultModel apiresult = new ApiResultModel();
         apiresult = oLifeStyleRepository.UpdatePatientLifeStyle(_objPLS);
         return(Json(new { Success = true, ApiResultModel = apiresult }));
     }
     catch (System.Web.Http.HttpResponseException ex)
     {
         return(Json(new { Message = ex.Response }));
     }
 }
Ejemplo n.º 3
0
 public ApiResultModel UpdatePatientLifeStyle(PatientLifeStyleModel model)
 {
     try
     {
         var strContent = JsonConvert.SerializeObject(model);
         var response   = ApiConsumerHelper.PostData("api/editPatientLifeStyle", strContent);
         var result     = JsonConvert.DeserializeObject <ApiResultModel>(response);
         return(result);
     }
     catch (HttpResponseException ex)
     {
         throw ex;
     }
 }