public static void SaveAnswer(LABAnswerModel pLABAnswerModel)
        {
            using (UpsilabEntities db = new UpsilabEntities())
            {
                var existingAnswer = db.LABAnswerModel.Where(la => la.idLABModel == pLABAnswerModel.idLABModel
                                                            && la.idLABQuestion == pLABAnswerModel.idLABQuestion).FirstOrDefault();

                //Insert / update
                if (existingAnswer == null) //Insert
                {
                    db.LABAnswerModel.AddObject(pLABAnswerModel);
                }
                else //update
                {
                    existingAnswer.idResponse = pLABAnswerModel.idResponse;
                    existingAnswer.idRisk = pLABAnswerModel.idRisk;
                    existingAnswer.idVigilance = pLABAnswerModel.idVigilance;
                    existingAnswer.DateUpdated = DateTime.Now;
                }

                //Commit
                db.SaveChanges();
            }
        }
        public JsonResult SaveStudyData()
        {
            object returnValue = new { status = "None" };
            Guid idLabModel;

            string prefixName = string.Empty;
            int questionId = 0;
            int responseId = 0;
            int riskId = 0;
            int vigilanceId = 0;

            try
            {
                if (Request.Form["name"] != null)
                {
                    //IdLabStudy
                    SessionManager.Get<Guid>(LABModelBL.IdLABModelSessionKey, out idLabModel);
                    if (idLabModel == null)
                    {
                        returnValue = new { status = "ExpiredSession" };
                        return Json(returnValue, JsonRequestBehavior.AllowGet); //TODO => expired session
                    }

                    LABModel labModel = LABModelBL.GetLABModelsById(idLabModel);

                    //Question, answer, risk, vigilance ID ?
                    string[] arrName = Request.Form["name"].Split(new char[] { '_' });
                    prefixName = arrName[0];
                    questionId = Convert.ToInt32(arrName[1]);
                    responseId = Convert.ToInt32(arrName[2]);
                    riskId = Convert.ToInt32(arrName[3]);
                    vigilanceId = Convert.ToInt32(arrName[4]);

                    //Insert / update Answer
                    LABAnswerModel labAnswer = new LABAnswerModel()
                    {
                        idLABAnswerModel = GuidHelper.GenerateGuid(),
                        idLABModel = idLabModel,
                        idLABQuestion = questionId,
                        idResponse = responseId,
                        idRisk = riskId,
                        idVigilance = vigilanceId,
                        DateCreated = DateTime.Now

                    };

                    //particular case for Question 7 (IdLabQuestion = 8) response yes
                    if (questionId == 8 && responseId == 1)
                    {
                        var firstQuestionAnswer = LABAnswerModelBL.GetLABAnswerModelByIdLABQuestion(idLabModel, 2); //idQuestion = 2 => first question
                        if (firstQuestionAnswer != null)
                        {
                            if (firstQuestionAnswer.idResponse == 1) //yes
                            {
                                labAnswer.idRisk = 2;
                                labAnswer.idVigilance = 3;
                            }
                            else if (firstQuestionAnswer.idResponse == 2) //no
                            {
                                labAnswer.idRisk = 3;
                                labAnswer.idVigilance = 5;
                            }
                        }
                    }

                    LABAnswerModelBL.SaveAnswer(labAnswer);

                    ////Evaluate LABStudy 
                    string labStatus = LABModelBL.EvaluateLABModel(labModel);

                    var returnObj = new { idRisk = labModel.idRisk, idVigilance = labModel.idVigilance, status = labStatus };
                    return Json(returnObj, JsonRequestBehavior.AllowGet);
                }

            }
            catch (Exception ex)
            {
                returnValue = new { status = "Exception" };
                Upsilab.Business.Log.Log.AppendException(ex);
            }

            return Json(returnValue, JsonRequestBehavior.AllowGet); ;
        }