public ActionResult Index() { try { if (Request.Params["LabModelName"] != null && Request.Params["LabModelIsPP"] != null) { var type = Request.Params["LabModelIsPP"]; LABModel obj = new LABModel(); obj.idLABModel = GuidHelper.GenerateGuid(); obj.Name = Request.Params["LabModelName"]; obj.DateCreated = DateTime.Now; obj.idUser = SessionManager.GetUserSession().idUser; obj.IsPP = type == "0" ? false : true; LABModelBL.InsertLABModel(obj); } } catch (Exception ex) { Business.Log.Log.AppendException(ex); } List<LABModel> lstLabModels = GetModeles(); return View("Index", lstLabModels); }
public static void InsertLABModel(LABModel labModel) { using (UpsilabEntities context = new UpsilabEntities()) { context.LABModel.AddObject(labModel); context.SaveChanges(); } }
public static string EvaluateLABModel(LABModel labModel) { string status = "InProgress"; if (LABModelBL.IsLABModelCompleted(labModel)) { var answerList = LABAnswerModelBL.GetLABAnswerModelsByIdLABModel(labModel.idLABModel); LABAnswerModel riskValue = null; LABAnswerModel vigilanceValue = null; using (UpsilabEntities context = new UpsilabEntities()) { var query = from answer in answerList join risk in context.RiskLevel on answer.idRisk equals risk.idRiskLevel orderby risk.RiskOrder descending select answer; riskValue = query.FirstOrDefault(); query = from answer in answerList join vigilance in context.VigilanceLevel on answer.idVigilance equals vigilance.idVigilanceLevel orderby vigilance.VigilanceOrder descending select answer; vigilanceValue = query.FirstOrDefault(); } if (riskValue != null) labModel.idRisk = riskValue.idRisk; if (vigilanceValue != null) labModel.idVigilance = vigilanceValue.idVigilance; status = "Completed"; } labModel.DateUpdated = DateTime.Now; LABModelBL.SaveLabModel(labModel); return status; }
public static Boolean IsLABModelCompleted(LABModel LABModel) { if (LABModel == null) return false; //get root questions by idCustomer isCorporation and construct question list var questionList = LABQuestionBL.GetLABQuestions(LABModel.IsPP); var answerList = LABAnswerModelBL.GetLABAnswerModelsByIdLABModel(LABModel.idLABModel); // count the question vs answers if (answerList.Count >= questionList.Count) //should be == but some evol obliged us to delete some questions return true; return false; }
private static void SaveLabModel(LABModel labModel) { using (UpsilabEntities db = new UpsilabEntities()) { var labM = db.LABModel.Where(lm => lm.idLABModel == labModel.idLABModel).FirstOrDefault(); if (labM != null) { labM.idRisk = labModel.idRisk; labM.idVigilance = labModel.idVigilance; labM.DateUpdated = labM.DateUpdated; db.SaveChanges(); } } }
public LABStudyModel GetLABModel(LABModel _labModel, int _questionParentID) { //1- Initialize LABStudyModel labStudyModel = new LABStudyModel(); labStudyModel.idParent = _questionParentID; labStudyModel.IsTemplate = true; labStudyModel.LabModel = _labModel; labStudyModel.idLABStudy = _labModel.idLABModel; // //2- Get LAB Questions ///TODO --> TargetPerson tjs = client. Voir comment traiter les prospects. labStudyModel.Customer = new CustomerProspect() { IsCustomer = true, IsCorporation = !_labModel.IsPP }; labStudyModel.LABQuestions = LABQuestionBL.GetLABQuestionListWithIdParent(_questionParentID, labStudyModel.Customer).ToList(); //3- Get LAB Answers var answers = LABAnswerModelBL.GetAnswersByIdParentQuestionAndIdCustomerProspect(labStudyModel); if (answers != null) { labStudyModel.LABTemplateAnswers = answers; } //4- Check if all questions have been answered this.CheckIfAllQuestionsAnswered(labStudyModel); //Set session ? SessionManager.Set<Guid>(LABModelBL.IdLABModelSessionKey, labStudyModel.LabModel.idLABModel); //5- Get options and options'value // labStudyModel.OptionData = GetLABStudyOptionModel(labStudyModel); labStudyModel.OptionData = new List<LABOptionModel>(); //6- Get Question assessments labStudyModel.QuestionAssessment = QuestionAssessmentBL.Get(); return labStudyModel; //} }
private static void ProcessUser(User user) { try { string statusInProgress = LABStudy.StatusEnum.InProgress.ToString(); string statusCompleted = LABStudy.StatusEnum.Completed.ToString(); string statusSentToCoffreFort = LABStudy.StatusEnum.SentToCoffreFort.ToString(); bool isSendTocoffreOk = false; //////// { // System.Console.WriteLine("\nTraitement de l'utilisateur : {0} {1}", user.UserName, user.UserFirstName); // int randomNumber = Rand(); _Log.Trace("Starting thread for {0} {1} from iteration {2} Thread count : {3} ", user.UserName, user.UserFirstName, _IterationId, _countThread); // Thread.Sleep(randomNumber); // _LstOfCommand.Enqueue(new GuidAction() { guid = user.idUser, action = "remove" }); // autoEvent.Set(); // _Log.Trace("Ending thread for {0} {1} from iteration {2}", user.UserName, user.UserFirstName, _IterationId); } // return; ////// //liste des CustomerProspectLABModel par utilisateur List<CustomerProspectLABModel> lstCustomerLABModels = new List<CustomerProspectLABModel>(); lstCustomerLABModels = LABStudyBL.GetCustomerLABModelInProgress(user.idUser); //boucle sur liste customer LABModel labModelNow = null; LABStudy labStudyNow = null; List<Guid> lstFailingGuid = new List<Guid>(); foreach (CustomerProspectLABModel customerLabModel in lstCustomerLABModels) { try { using (UpsilabEntities db = new UpsilabEntities()) { //LABModel d'un utilisateur en cour labModelNow = new LABModel(); labModelNow = db.LABModel.Where(l => l.idUser == user.idUser && l.idLABModel == customerLabModel.idLABModel).FirstOrDefault(); //copy LABModel vers LABStudy labStudyNow = new LABStudy() { idLABStudy = GuidHelper.GenerateGuid(), idCustomer = customerLabModel.idCustomerProspect, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, Status = statusInProgress, idRisk = labModelNow.idRisk, idVigilance = labModelNow.idVigilance }; db.LABStudy.AddObject(labStudyNow); _Log.Trace("\nApplication du modele LAB : {0} au client : {1} {2}", labModelNow.Name, customerLabModel.CustomerProspect.Name, customerLabModel.CustomerProspect.User.UserFirstName); //liste des question/reponse (LABAnswerModel) List<LABAnswerModel> lstanswermodel = new List<LABAnswerModel>(); lstanswermodel = db.LABAnswerModel.Where(lam => lam.idLABModel == labModelNow.idLABModel).ToList(); //copy LABAnswerModel vers LABAnswer foreach (LABAnswerModel lam in lstanswermodel) { LABAnswer LABAnswerNow = new LABAnswer() { idLABAnswer = GuidHelper.GenerateGuid(), idLABStudy = labStudyNow.idLABStudy, idLABQuestion = lam.idLABQuestion, idResponse = lam.idResponse, idRisk = lam.idRisk, idVigilance = lam.idVigilance, DateCreated = DateTime.Now, DateUpdated = DateTime.Now }; db.LABAnswer.AddObject(LABAnswerNow); } labStudyNow.idElectronicSafeDocument = null; labStudyNow.Status = statusCompleted; //envoie la transaction db.SaveChanges(); } if (labStudyNow != null) { _Log.Trace("Début envoi de la LAB au coffre-fort"); //ElectronicSafeDocument Guid idElectronicSafeDocument = Guid.Empty; idElectronicSafeDocument = LABStudyBL.SendToCoffreFort(labStudyNow.idCustomer, labStudyNow.idLABStudy); if (idElectronicSafeDocument != Guid.Empty) { isSendTocoffreOk = true; using (UpsilabEntities db = new UpsilabEntities()) { //update CustomerProspectLABModel customerLAbModeltoupdate = db.CustomerProspectLABModel.Where(c => c.idCustomerProspectLABModel == customerLabModel.idCustomerProspectLABModel).FirstOrDefault(); customerLAbModeltoupdate.Status = statusCompleted; customerLAbModeltoupdate.DateUpdated = DateTime.Now; //update customerprospect CustomerProspect customerToUpdate = db.CustomerProspect.Where(c => c.idCustomer == customerLabModel.idCustomerProspect).FirstOrDefault(); customerToUpdate.CurrentLabStatus = statusSentToCoffreFort; //envoie la transaction db.SaveChanges(); } _Log.Trace("Envoi au coffre-fort OK"); } else { lstFailingGuid.Add(customerLabModel.CustomerProspect.IdUser); _Log.Trace("Erreur envoi au coffre-fort"); } } } catch (Exception exc) { lstFailingGuid.Add(customerLabModel.CustomerProspect.IdUser); _Log.Trace("Erreur pour le customer : {0}", customerLabModel.CustomerProspect.IdUser.ToString()); } if (_CancelToken.IsCancellationRequested) break; } //ajout nouveau message pour un utilisateur quand l'affectation LAB est fini if (lstFailingGuid.Count == 0) { using (UpsilabEntities db = new UpsilabEntities()) { Message msg = new Message() { idUser = user.idUser, NameKey = LABStudyBL.MessageNamekey, Read = false, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, idLABModel = labModelNow.idLABModel, From = LABStudyBL.FromLABModel }; db.Message.AddObject(msg); //envoie la transaction db.SaveChanges(); } _Log.Trace("\n Aucun incident pour l'utilisateur"); } else { using (UpsilabEntities db = new UpsilabEntities()) { Message msg = new Message() { idUser = user.idUser, NameKey = LABStudyBL.MessageNamekeyKO, Read = false, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, idLABModel = labModelNow.idLABModel, From = LABStudyBL.FromLABModel, AdditionnalContent = String.Join(";", lstFailingGuid.ToArray()) }; db.Message.AddObject(msg); //envoie la transaction db.SaveChanges(); } _Log.Trace("\n Erreur survenue pour l'utilisateur"); } } catch (Exception ex) { _Log.Trace("Exception : {0}", ex.Message); Log.AppendException(ex); } finally { _LstOfCommand.Enqueue(new GuidAction() { guid = user.idUser, action = "remove" }); autoEvent.Set(); _Log.Trace("Ending thread for {0} {1} from iteration {2}", user.UserName, user.UserFirstName, _IterationId); } // RemoveItemToLstOfProcessingUser(user); }