public ActionResult ConventionManuelleCoffreFort(ConventionVM conventionVM)
        {
            bool bOk = true;
            var error = string.Empty;

            try
            {
                var firmCGP = SessionManager.GetFirmInstutionCGPSession();
                var firmSDG = SessionManager.GetFirmInstitutionSession();

                if (firmCGP == null)
                {
                    return RedirectToPageIfCGPNotDefined();
                }

                //Signature date ?
                var signatureDate = DateTime.Now;
                DateTime.TryParse(conventionVM.StrDateSignature, out signatureDate);

                if (signatureDate == DateTime.MinValue)
                {
                    signatureDate = DateTime.Now;
                }

                //Get document to send to coffre fort
                var signedDocuments = DocumentBL.GetDocuments(conventionVM.IdTransaction, DocumentBL.Status.ToCoffreFort);

                //Send to coffre
                var clientD3S = new Upsilab.Infrastructure.DICTAO.D3S.D3SClient();

                foreach (var document in signedDocuments)
                {
                    try
                    {
                        //1- Copy to directory
                        var sourceFilePath = FileManager.GetFileFromUploadDirectory(document.Location, document.Name);

                        var relativePath = string.Empty;
                        var fullPath = ElectronicSafeDocumentBL.BuildSignatureDocumentPath(firmCGP.FirmInstitutionName, firmCGP.idFirmInstitution, document.DocumentType.ToDocumentTypeEnum(), false, out relativePath); //CF
                        var destFileName = ElectronicSafeDocumentBL.BuildDocumentName(document.DocumentType, document.idDocument);
                        var destFilePath = Path.Combine(fullPath, destFileName);

                        if (!System.IO.File.Exists(destFilePath))
                        {
                            System.IO.File.Copy(sourceFilePath, destFilePath);

                            //2- Send to dictao
                            var dictaoId = ElectronicSafeDocumentBL.SendToDictaoCoffreFort(sourceFilePath.Replace(document.Name, string.Empty),
                                document.Name, clientD3S);

                            if (!string.IsNullOrEmpty(dictaoId))
                            {
                                var documentLabel = Upsilab.Business.Language.LanguageContentBL.Translate(document.DocumentType.ToLower());
                                ElectronicSafeDocumentBL.SaveDocumentToDB(destFileName, document.DocumentType, documentLabel, relativePath, firmCGP.idFirmInstitution, dictaoId, clientD3S, false, document.IdDocumentCategory, null, conventionVM.IdTransaction);
                            }

                        }

                    }
                    catch (Exception ex)
                    {
                        Log.AppendException(ex);
                    }
                }

                //Soustraire 1 credit
                var transaction = DocumentSignatureTransactionBL.GetTransactionById(conventionVM.IdTransaction);
                CreditOperationBL.SubstractCredit(firmSDG.idFirmInstitution, CreditOperationBL.OperationType.MISE_AU_COFFRE_MANUELLE_SDG_CONVENTION.ToString(), transaction.idUserCreated);

                //Update status to "Completed" 
                DocumentSignatureTransactionBL.UpdateTransactionStatus(conventionVM.IdTransaction, DocumentBL.Status.Completed, signatureDate);
            }
            catch (Exception ex)
            {
                bOk = false;
                error = ex.Message;
            }

            //Show view info
            var languageData = Upsilab.Business.Utility.PageLanguageHelper.GetLanguageContent("User", "Convention");
            var languageDataSignature = Upsilab.Business.Utility.PageLanguageHelper.GetLanguageContent("User", "SignatureView");

            MessageViewModel messageVM = new MessageViewModel()
            {
                HeadTitle = languageDataSignature.GetContent("signature_signature"),
                H1Title = languageData.GetContent("convention_title"),
                H1Subtitle = languageDataSignature.GetContent("signature_signature"),
                IsError = !bOk,
                ErrorMessage = error
            };

            if (bOk)
            {
                messageVM.TableTitle = languageDataSignature.GetContent("signature_success_title");
                messageVM.Content = languageDataSignature.GetContent("signature_success_message");
            }
            else
            {
                messageVM.TableTitle = languageDataSignature.GetContent("signature_error_title");
                messageVM.Content = languageDataSignature.GetContent("signature_error_message");
            }

            return View("Message", messageVM);
        }
        private void GetMessage()
        {
            if (SessionManager.Exists(MISSION_DOC_MESSAGE))
            {
                MessageViewModel message = new MessageViewModel();
                SessionManager.Get<MessageViewModel>(MISSION_DOC_MESSAGE, out message);

                if (message.IsError)
                {
                    ViewBag.Error = message.Content;
                }
                else
                {
                    ViewBag.Ok = message.Content;
                }

                SessionManager.Clear(MISSION_DOC_MESSAGE);
            }
        }
        public ActionResult EnvoyerEmailDeRappel()
        {
            var bOk = true;
            var error = string.Empty;

            try
            {
                Guid? idTransaction;
                SessionManager.Get<Guid?>(CURRENT_SIGNATURE_TRANSACTION_ID, out idTransaction);
                bool isConvention = true;

                if (idTransaction == null)
                {
                    return RedirectToPageIfCGPNotDefined();
                }

                //Send reminder email                   
                DocumentSignatureTransactionBL.SendReminderEmail(idTransaction.Value, isConvention);
            }
            catch (Exception ex)
            {
                Business.Log.Log.AppendException(ex);
                error = ex.Message;
                bOk = false;
            }

            var languageData = Upsilab.Business.Utility.PageLanguageHelper.GetLanguageContent("User", "Convention");
            MessageViewModel messageVM = new MessageViewModel()
            {
                HeadTitle = languageData.GetContent("reminder_email"),
                H1Title = languageData.GetContent("convention_title"), //avenant ??
                H1Subtitle = languageData.GetContent("reminder_email"),
                IsError = !bOk,
                ErrorMessage = error
            };

            if (bOk)
            {
                messageVM.TableTitle = languageData.GetContent("reminder_email_success_title");
                messageVM.Content = languageData.GetContent("reminder_email_success");
            }
            else
            {
                messageVM.TableTitle = languageData.GetContent("reminder_email_error_title");
                messageVM.Content = languageData.GetContent("reminder_email_error");
            }

            return View("Message", messageVM);
        }
        private void SetMessage()
        {
            if (!string.IsNullOrEmpty(ViewBag.Error))
            {
                MessageViewModel message = new MessageViewModel()
                {
                    Content = ViewBag.Error,
                    IsError = true
                };

                SessionManager.Set<MessageViewModel>(MISSION_DOC_MESSAGE, message);
            }
            else if (!string.IsNullOrEmpty(ViewBag.Ok))
            {
                MessageViewModel message = new MessageViewModel()
                {
                    Content = ViewBag.Ok,
                    IsError = false
                };

                SessionManager.Set<MessageViewModel>(MISSION_DOC_MESSAGE, message);
            }
        }
        public ActionResult EnvoyerPourApprobation()
        {
            var bOk = true;
            var error = string.Empty;
            bool isConvention = false; //Avenant

            try
            {
                Guid? idTransaction;
                SessionManager.Get<Guid?>(CURRENT_SIGNATURE_TRANSACTION_ID, out idTransaction);

                if (idTransaction == null)
                {
                    return RedirectToPageIfCGPNotDefined();
                }

                //Check if one Avenant document is defined for the transaction
                var docsCount = DocumentBL.CountDocuments(idTransaction.Value);
                if (docsCount == 0)
                {
                    bOk = false;
                    error = _languageDataAvenant.GetContent("no_avenant_documents");
                }
                else
                {
                    //Send for approval
                    DocumentSignatureTransactionBL.SendForApproval(idTransaction.Value, isConvention);
                }
            }
            catch (Exception ex)
            {
                Business.Log.Log.AppendException(ex);
                error = ex.Message;
                bOk = false;
            }

            MessageViewModel messageVM = new MessageViewModel()
            {
                HeadTitle = _languageDataConvention.GetContent("approval"),
                H1Title = _languageDataAvenant.GetContent("avenant"),
                H1Subtitle = _languageDataConvention.GetContent("approval"),
                IsError = !bOk,
                ErrorMessage = error
            };

            if (bOk)
            {
                messageVM.TableTitle = _languageDataConvention.GetContent("approval_success_title");
                messageVM.Content = _languageDataConvention.GetContent("approval_success");
            }
            else
            {
                messageVM.TableTitle = _languageDataConvention.GetContent("approval_error_title");
                messageVM.Content = _languageDataConvention.GetContent("approval_error");
            }

            return View("Message", messageVM);
        }
        public ActionResult QuestionnairePdf(string printall = "yes")
        {
            Guid idReport = new Guid();
            Report report = null;
            string error = string.Empty;
            bool bOk = true;
            IDictionary<string, int> tabPatrimoineResume = new Dictionary<string, int>();
            bool inclureTableauxVide = false;

            if (!string.IsNullOrEmpty(printall))
            {
                if (printall.ToLower() == "yes")
                {
                    inclureTableauxVide = true;
                }
                else if (printall.ToLower() == "no")
                {
                    inclureTableauxVide = false;
                }
            }

            try
            {
                //Get id report
                SessionManager.Get<Guid>(ReportBL.IdReportSessionKey, out idReport);

                if (idReport == Guid.Empty || idReport == null)
                {
                    error = LanguageData.GetContent("report_no_report_to_print");
                    bOk = false;
                }

                if (bOk)
                {
                    //Get report
                    report = ReportBL.GetReportById(idReport);
                    if (report == null)
                    {
                        error = LanguageData.GetContent("report_no_report_to_print");
                        bOk = false;
                    }
                    else
                    {
                        // File to sign ?
                        bool isPP = (report.CustomerProspect.IsCorporation.HasValue) ? ((report.CustomerProspect.IsCorporation.Value) ? false : true) : false;
                        if (isPP)
                        {
                            if (!inclureTableauxVide)
                            {
                                Upsilab.Business.Report.ReportBL.GeneratePPReport(idReport, string.Empty, true); //Force download
                            }
                            else
                            {
                                Upsilab.Business.Report.ReportBL.GeneratePPReport(idReport, string.Empty, true, false, inclureTableauxVide); //Force download
                            }
                        }
                        else
                        {
                            Upsilab.Business.Report.ReportBL.GeneratePMReport(idReport, string.Empty, true); //Force download
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //error = ex.StackTrace;
                error = ex.Message;
                bOk = false;
            }

            MessageViewModel messageVM = new MessageViewModel()
            {
                HeadTitle = LanguageData.GetContent("report_print_title"),
                H1Title = LanguageData.GetContent("report_title"),
                H1Subtitle = LanguageData.GetContent("report_print_title2"),
                IsError = !bOk,
                ErrorMessage = error
            };

            if (!bOk)
            {
                messageVM.TableTitle = LanguageData.GetContent("report_print_error_title");
                messageVM.Content = LanguageData.GetContent("report_print_error");
            }

            return View("Message", messageVM);
        }
        public ActionResult AnnulerQuestionnaireEnvoyeAuClient()
        {
            Guid idReport = new Guid();
            Report report = null;
            string error = string.Empty;
            bool bOk = true;

            try
            {
                //Get id report
                SessionManager.Get<Guid>(ReportBL.IdReportSessionKey, out idReport);

                if (idReport == Guid.Empty || idReport == null)
                {
                    error = LanguageData.GetContent("report_no_report_to_cancel");
                    bOk = false;
                }

                if (bOk)
                {
                    //Get report
                    report = ReportBL.GetReportById(idReport);
                    if (report == null)
                    {
                        error = LanguageData.GetContent("report_no_report_to_cancel");
                        bOk = false;
                    }
                    else if (report.Status.ToLower() == ReportBL.Status.Canceled.ToString().ToLower()) // check if already canceled
                    {
                        error = LanguageData.GetContent("report_already_canceled");
                        bOk = false;
                    }
                    else
                    {
                        report.Status = ReportBL.Status.InProgress.ToString(); //Non pas "Canceled" puisqu'on conserve les données
                        ReportBL.UpdateReport(report);

                        //Mettre à jour CurrentReportStatus du client.
                        CustomerProspect cust = CustomerProspectBL.GetCustomerProspectById(report.idCustomerProspect);
                        cust.CurrentReportStatus = report.Status;
                        CustomerProspectBL.Update(cust);
                    }
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                bOk = false;
            }

            MessageViewModel messageVM = new MessageViewModel()
            {
                HeadTitle = LanguageData.GetContent("report_cancel_title"),
                H1Title = LanguageData.GetContent("report_title"),
                H1Subtitle = LanguageData.GetContent("report_cancel_title2"),
                IsError = !bOk,
                ErrorMessage = error
            };

            if (bOk)
            {
                messageVM.TableTitle = LanguageData.GetContent("report_cancel_success_title");
                messageVM.Content = LanguageData.GetContent("report_cancel_success");
            }
            else
            {
                messageVM.TableTitle = LanguageData.GetContent("report_cancel_error_title");
                messageVM.Content = LanguageData.GetContent("report_cancel_error");
            }

            return View("Message", messageVM);
        }
        public ActionResult ReleveSituation(string idclient)
        {
            var LanguageData = PageLanguageHelper.GetLanguageContent("User", "Recueil");
            var iserror = true;
            var errormsg = string.Empty;
            try
            {
                Guid idCgpAgreg = Guid.Empty;
                User currentUser = SessionManager.GetUserSession();
                if (currentUser.IsEndUser())
                {
                    CustomerProspect currentCustomer = SessionManager.GetCustomerProspectSession();
                    User currenttUserCreated = currentCustomer.User1;
                    idCgpAgreg = currenttUserCreated.idAgregCGP.Value;
                }
                else
                {
                    idCgpAgreg = currentUser.idAgregCGP.Value;
                }
                //
                Guid idFirm = Guid.Empty;
                SessionManager.Get<Guid>(UserBL.AgregCurrentUserFirmId, out idFirm);
                FirmInstitution firm = null;
                if (idFirm == Guid.Empty)
                {
                    if (currentUser != null && currentUser.idAgregCGP.HasValue)
                    {
                        var cgp = AgregCgpBL.GetCgpById(idCgpAgreg);
                        firm = FirmInstitutionBL.GetFirmInstitutionByIdAgregCabinet(cgp.idcrmcabinet);
                        if (firm != null)
                        {
                            SessionManager.Set<Guid>(UserBL.AgregCurrentUserFirmId, firm.idFirmInstitution);
                            idFirm = firm.idFirmInstitution;
                        }
                    }
                }
                AgregReleverSituationBL.GenererReleveSituation(idCgpAgreg.ToString(), idclient, string.Empty, true, 1, string.Empty,idFirm);
            }
            catch (Exception ex)
            {
                errormsg = ex.Message;
                iserror = false;
                Upsilab.Business.Log.Log.AppendException(ex);
            }

            MessageViewModel messageVM = new MessageViewModel()
            {
                HeadTitle = LanguageData.GetContent("report_print_title"),
                H1Title = LanguageData.GetContent("report_title"),
                H1Subtitle = LanguageData.GetContent("report_print_title2"),
                IsError = !iserror,
                ErrorMessage = errormsg
            };

            if (!iserror)
            {
                messageVM.TableTitle = LanguageData.GetContent("report_print_error_title");
                messageVM.Content = LanguageData.GetContent("report_print_error");
            }

            return View("Message", messageVM);
        }