Exemple #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="Signature"/> using the given parameters.
        /// </summary>
        /// <param name="sigBa">Byte array containing the signature</param>
        /// <param name="encoding">Incicates encoding used in the given byte array</param>
        public Signature(byte[] sigBa, SigEncoding encoding)
        {
            derEnc = new DER();

            if (encoding == SigEncoding.Der)
            {
                int offset = 0;
                if (!derEnc.TryDecode2Integers(sigBa, ref offset, true, out _r, out _s, out string error))
                {
                    throw new FormatException(error);
                }
            }
            else if (encoding == SigEncoding.WithRecId)
            {
                if (sigBa.Length != 65)
                {
                    throw new FormatException("Invalid length.");
                }

                RecoveryId = sigBa[0];
                R          = sigBa.SubArray(1, 32).ToBigInt(true, true);
                S          = sigBa.SubArray(33, 32).ToBigInt(true, true);
            }
            else
            {
                throw new ArgumentException("Encoding is not defined.", nameof(encoding));
            }
        }
Exemple #2
0
        public NetworkEntitiesViewModel()
        {
            currentDER = new DER()
            {
                Id = 0, EnergyValue = "1", Name = "temp"
            };
            removeDER = new DER();
            filterDER = new DER()
            {
                Id = 0, EnergyValue = "1", Name = "temp"
            };

            DERs = new BindingList <DER>();

            fillList();

            AddDERCommand               = new MyICommand(OnAdd, CanAdd);
            DeleteDERCommand            = new MyICommand(OnDelete, CanDelete);
            FilterComboBoxDERCommand    = new MyICommand(OnFilterComboBox, CanFilter);
            FilterRadioButtonDERCommand = new MyICommand <StackPanel>(OnFilterRadioButtonDER, CanFilterrRadioButton);

            SelectedItemChangedCommand          = new MyICommand <DER>(OnSelectedItemChanged);
            LoadStackPanelCommand               = new MyICommand <StackPanel>(OnLoadStackPanel);
            SelectedItemChangedComboBox1Command = new MyICommand <string>(OnSelectedItemChangedComboBox1);
            SelectedItemChangedComboBox2Command = new MyICommand <string>(OnSelectedItemChangedComboBox2);
            FilterComboDERCommand               = new MyICommand <StackPanel>(OnFilterComboDER, CanFilterComboDER);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of <see cref="Signature"/> using the given parameters.
        /// </summary>
        /// <param name="r">R value</param>
        /// <param name="s">S value</param>
        /// <param name="v">Recovery ID</param>
        public Signature(BigInteger r, BigInteger s, byte?v = null)
        {
            derEnc = new DER();

            R          = r;
            S          = s;
            RecoveryId = v;
        }
Exemple #4
0
        private DER ProcessIncomming(string incomming)
        {
            DER temp = new DER();

            temp.Id   = int.Parse(incomming.Split(':')[0].Split('_')[1]);
            temp.Name = incomming.Split(':')[0];

            if (int.Parse(incomming.Split(':')[1]) >= 1 && int.Parse(incomming.Split(':')[1]) <= 5) // Validation
            {
                temp.EnergyValue = incomming.Split(':')[1] + " MW";
            }
            else
            {
                temp.EnergyValue = "Nevažeća dolazna vrednost!";
            }

            return(temp);
        }
Exemple #5
0
 private void OnSelectedItemChanged(DER removeDER)
 {
     RemoveDER = removeDER;
 }
        private List<DocumentToSign> GetDocumentsToSign(DER der)
        {
            string error = string.Empty;
            int pageCount = 0;
            CustomerProspect customer = der.CustomerProspect;
            List<DocumentToSign> documentsToSign = new List<DocumentToSign>();


            #region 1- Fiche d'information legale FIL => DER
                    List<SignatureParameter> signatureParametersDER = new List<SignatureParameter>();
                    //A- PDF ?
                    pageCount = 0;
                    string docType = ElectronicSafeDocumentBL.DocumentType.FIL.ToString();
                    string firmDocumentPath = string.Format(@"{0}\FirmInstitution\FI_{1}", Server.MapPath("~/uploads"), der.CustomerProspect.FirmInstitution.idFirmInstitution);
                    string destFullPath = ElectronicSafeDocumentBL.BuildClientUploadDocumentPath(docType, customer);
                    string filename = ElectronicSafeDocumentBL.BuildDocumentName(docType, der.idDer, false);

                    string destFILFilePath = System.IO.Path.Combine(destFullPath, filename);

                    //From firmModel or from upsideomodel
                    if (der.IsDerFromModel)
                    {
                        //Merge pdf
                        filename = der.CustomerProspect.FirmInstitution.LegalInformationFile;
                        string uploadedDoc = System.IO.Path.Combine(firmDocumentPath, filename);

                        if (System.IO.File.Exists(uploadedDoc))
                        {
                            Upsilab.Business.Configuration.FirmInstitutionPdfGeneration.GenerateDERByMerge(der.CustomerProspect.FirmInstitution, uploadedDoc, destFILFilePath, false, out pageCount);
                        }
                        else
                        {
                            error = _languageData.GetContent("le_pdf_doc_entree_en_relation_n_existe_pas");
                        }

                    }
                    else
                    {
                        //From upsideo model => generate it
                        pageCount = Upsilab.Business.Configuration.FirmInstitutionPdfGeneration.GenerateDER(der.CustomerProspect.FirmInstitution, der.CustomerProspect.idCustomer, destFILFilePath, false);
                    }

                    if (!System.IO.File.Exists(destFILFilePath))
                    {
                        error = _languageData.GetContent("le_pdf_doc_entree_en_relation_n_existe_pas");
                    }
                    else
                    {
                        //B- Prepare object to send to signature
                        SignatureParameter signatureParameter = new SignatureParameter()
                        {
                            SignatureFieldLabel = DTPClient.USER_ADVISER,

                            SignaturePosition = new SignaturePosition()
                            {
                                Page = (pageCount > 0) ? pageCount : 16, //DER : 16pages
                                X = 33,
                                Y = 177
                            }
                        };

                        signatureParametersDER.Add(signatureParameter);

                        signatureParameter = new SignatureParameter()
                        {
                            SignatureFieldLabel = DTPClient.USER_CUSTOMER,

                            SignaturePosition = new SignaturePosition()
                            {
                                Page = (pageCount > 0) ? pageCount : 16, //DER : 16pages
                                X = 120,
                                Y = 177
                            }
                        };

                        signatureParametersDER.Add(signatureParameter);

                        DocumentToSign docDER = new DocumentToSign()
                        {
                            Label = _languageData.GetContent("doc_entree_en_relation"),
                            Description = _languageData.GetContent("doc_entree_en_relation"),
                            PathFilename = destFILFilePath,
                            Type = DTPClient.DocumentTypes.CONTRACT.ToString(),
                            SignatureParameters = signatureParametersDER
                        };

                        documentsToSign.Add(docDER);
                    }
                
            
            #endregion

            #region 2- Presentation etablissement
            if (der.AttachPresentation)
            {
                List<SignatureParameter> signatureParametersBS = new List<SignatureParameter>();
                //A- PDF ?
                pageCount = 0;
                docType = ElectronicSafeDocumentBL.DocumentType.BS.ToString();
                firmDocumentPath = string.Format(@"{0}\FirmInstitution\FI_{1}", Server.MapPath("~/uploads"), der.CustomerProspect.FirmInstitution.idFirmInstitution);
                destFullPath = ElectronicSafeDocumentBL.BuildClientUploadDocumentPath(docType, customer);
                filename = ElectronicSafeDocumentBL.BuildDocumentName(docType, der.idDer, false);

                string destBSFilePath = System.IO.Path.Combine(destFullPath, filename);

                //From firmModel or from upsideomodel
                if (der.IsPresentationFromModel)
                {
                    //Merge pdf
                    filename = der.CustomerProspect.FirmInstitution.PresentationFile;
                    string uploadedDoc = System.IO.Path.Combine(firmDocumentPath, filename);

                    if (System.IO.File.Exists(uploadedDoc))
                    {
                        Upsilab.Business.Configuration.FirmInstitutionPdfGeneration.GeneratePresentationByMerge(der.CustomerProspect.FirmInstitution, uploadedDoc, destBSFilePath, false, out pageCount);
                    }
                    else
                    {
                        error = _languageData.GetContent("pdf_presentation_etab_n_existe_pas_ou");
                    }

                }
                else
                {
                    //From upsideo model => generate it
                    Upsilab.Business.Configuration.FirmInstitutionPdfGeneration.GeneratePresentation(der.CustomerProspect.FirmInstitution, destBSFilePath, false);
                }

                if (!System.IO.File.Exists(destBSFilePath))
                {
                    error = _languageData.GetContent("pdf_presentation_etab_n_existe_pas_ou");
                }
                else
                {
                    //B- Prepare object to send to signature
                    SignatureParameter signatureParameter = new SignatureParameter()
                    {
                        SignatureFieldLabel = DTPClient.USER_ADVISER,

                        SignaturePosition = new SignaturePosition()
                        {
                            Page = (pageCount > 0) ? pageCount : 6, //BS : 6pages
                            X = 33,
                            Y = 177
                        }
                    };

                    signatureParametersBS.Add(signatureParameter);

                    signatureParameter = new SignatureParameter()
                    {
                        SignatureFieldLabel = DTPClient.USER_CUSTOMER,

                        SignaturePosition = new SignaturePosition()
                        {
                            Page = (pageCount > 0) ? pageCount : 6, //BS : 6pages
                            X = 120,
                            Y = 177
                        }
                    };

                    signatureParametersBS.Add(signatureParameter);


                    DocumentToSign docPE = new DocumentToSign()
                    {
                        Label = _languageData.GetContent("presentation_de_l_etab"),
                        Description = _languageData.GetContent("presentation_de_l_etab"),
                        PathFilename = destBSFilePath,
                        Type = DTPClient.DocumentTypes.APPENDIX1.ToString(),
                        SignatureParameters = signatureParametersBS
                    };

                    documentsToSign.Add(docPE);
                }
            }
            #endregion

            return documentsToSign;

        }
        public ActionResult SignerDERParConseiller(string id)
        {
            string error = string.Empty;
            string urlIHM_Dictao = string.Empty;
            DER der = new DER();
            List<DocumentToSign> documentsToSign = new List<DocumentToSign>();

            try
            {
                // Id DER doc = id in parameter                
                der = DerBL.GetDERById(new Guid(id));

                if (der == null)
                {
                    error = _languageData.GetContent("selectionner_un_doc_a_signer");
                }
                else
                {
                    documentsToSign = this.GetDocumentsToSign(der); //TODO generate pdf ?

                    //Signature
                    if (documentsToSign.Count == 0)
                    {
                        error = _languageData.GetContent("aucun_doc_a_signer_veuillez");
                    }

                    if (string.IsNullOrEmpty(error))
                    {
                        // Sign the document mission
                        Upsilab.Data.Model.User userAdviser = (der.User != null) ? der.User : Upsilab.Business.Utility.SessionManager.GetUserSession();
                        urlIHM_Dictao = SignatureDocumentBL.SignDERByAdviser(der.idDer, documentsToSign, userAdviser);
                    }
                }
            }
            catch (Exception ex)
            {
                Upsilab.Business.Log.Log.AppendException(ex);
                error = ex.Message;
            }

            if (!string.IsNullOrEmpty(error))
            {
                SignatureModel signatureModel = new SignatureModel()
                {
                    H1Title = Business.Language.LanguageContentBL.Translate("der_title"),
                    HeadTitle = string.Format("Signature {0}", Business.Language.LanguageContentBL.Translate("der_title")),
                    ErrorMessage = error
                };

                return View("AllerSignature", signatureModel);
            }
            else
            {
                return Redirect(urlIHM_Dictao);
            }

        }
        public ActionResult SignerDERParClient(string id)
        {
            string error = string.Empty;
            string urlIHM_Dictao = string.Empty;
            int pageCount = 0;
            DER der = new DER();

            try
            {
                // Id latest mission document = id in parameter                
                if (string.IsNullOrEmpty(id))
                {
                    error = _languageData.GetContent("selectionner_un_doc_a_signer");
                }
                else
                {
                    der = DerBL.GetDERById(new Guid(id));

                    if (der == null)
                    {
                        error = _languageData.GetContent("selectionner_un_doc_a_signer");
                    }
                    else
                    {
                        List<DocumentToSign> documentsToSign = this.GetDocumentsToSign(der); //TODO generate pdf ?

                        // Sign the mission document (Customer signs secondly)
                        urlIHM_Dictao = SignatureDocumentBL.SignDERByCustomer(der.idDer, documentsToSign, pageCount);
                    }
                }
            }
            catch (Exception ex)
            {
                Upsilab.Business.Log.Log.AppendException(ex);
                error = ex.Message;
            }

            if (!string.IsNullOrEmpty(error))
            {
                SignatureModel signatureModel = new SignatureModel()
                {
                    H1Title = Business.Language.LanguageContentBL.Translate("der_title"),
                    HeadTitle = string.Format(_languageData.GetContent("signature_"), Business.Language.LanguageContentBL.Translate("der_title")),
                    ErrorMessage = error
                };

                return View("AllerSignature", signatureModel);
            }
            else
            {
                return Redirect(urlIHM_Dictao);
            }
        }
Exemple #9
0
        private void createListener()
        {
            var tcp = new TcpListener(IPAddress.Any, 25565);

            tcp.Start();

            var listeningThread = new Thread(() =>
            {
                while (true)
                {
                    var tcpClient = tcp.AcceptTcpClient();
                    ThreadPool.QueueUserWorkItem(param =>
                    {
                        //Prijem poruke
                        NetworkStream stream = tcpClient.GetStream();
                        string incomming;
                        byte[] bytes = new byte[1024];
                        int i        = stream.Read(bytes, 0, bytes.Length);
                        //Primljena poruka je sacuvana u incomming stringu
                        incomming = System.Text.Encoding.ASCII.GetString(bytes, 0, i);

                        //Ukoliko je primljena poruka pitanje koliko objekata ima u sistemu -> odgovor
                        if (incomming.Equals("Need object count"))
                        {
                            //Response

                            /* Umesto sto se ovde salje count.ToString(), potrebno je poslati
                             * duzinu liste koja sadrzi sve objekte pod monitoringom, odnosno
                             * njihov ukupan broj (NE BROJATI OD NULE, VEC POSLATI UKUPAN BROJ)
                             * */
                            Byte[] data = System.Text.Encoding.ASCII.GetBytes(NetworkEntitiesViewModel.savedDERs.Count().ToString());
                            stream.Write(data, 0, data.Length);
                        }
                        else
                        {
                            //U suprotnom, server je poslao promenu stanja nekog objekta u sistemu
                            Console.WriteLine(incomming); //Na primer: "Entitet_1:272"

                            //################ IMPLEMENTACIJA ####################
                            // Obraditi poruku kako bi se dobile informacije o izmeni
                            // Azuriranje potrebnih stvari u aplikaciji

                            incommingDER = ProcessIncomming(incomming);

                            using (StreamWriter writetext = new StreamWriter("log.txt"))
                            {
                                writetext.WriteLine(DateTime.Now + "/" + incomming);
                            }
                            Messenger.Default.Send <CustomMessenger>(new CustomMessenger(incommingDER.Id, incommingDER.Name, incommingDER.EnergyValue, incommingDER.Type));

                            if (NetworkEntitiesViewModel.DERs.ToList().FirstOrDefault(x => x.Id == incommingDER.Id) != null)
                            {
                                foreach (var item in NetworkEntitiesViewModel.DERs.ToList())
                                {
                                    if (item.Id == incommingDER.Id)
                                    {
                                        item.EnergyValue = incommingDER.EnergyValue;
                                        item.Name        = incommingDER.Name;
                                    }
                                }
                                foreach (var item in NetworkEntitiesViewModel.savedDERs.ToList())
                                {
                                    if (item.Id == incommingDER.Id)
                                    {
                                        item.EnergyValue = incommingDER.EnergyValue;
                                        item.Name        = incommingDER.Name;
                                    }
                                }
                            }

                            if (NetworkDisplayViewModel.DisplayDERs.ToList().FirstOrDefault(x => x.Id == incommingDER.Id) != null)
                            {
                                foreach (var item in NetworkDisplayViewModel.DisplayDERs.ToList())
                                {
                                    if (item.Id == incommingDER.Id)
                                    {
                                        item.EnergyValue = incommingDER.EnergyValue;
                                        item.Name        = incommingDER.Name;
                                        item.ChanageImage();
                                    }
                                }
                            }
                        }
                    }, null);
                }
            });

            listeningThread.IsBackground = true;
            listeningThread.Start();
        }
        public ActionResult SignerDERParConseiller(string id)
        {
            string error = string.Empty;
            string urlIHM_Dictao = string.Empty;
            int pageCount = 0;
            DER der = new DER();
            List<DocumentToSign> documentsToSign = new List<DocumentToSign>();

            try
            {
                // Id mission doc = id in parameter                
                der = DerBL.GetDERById(new Guid(id));

                if (der == null)
                {
                    error = LanguageData.GetContent("selectionner_un_doc_a_signer");
                }
                else
                {
                    CustomerProspect customer = der.CustomerProspect;
                    SignatureParameters signatureParameters = null;

                    #region 1- Fiche d'information legale FIL => DER
                    //A- PDF ?
                    pageCount = 0;
                    string docType = ElectronicSafeDocumentBL.DocumentType.FIL.ToString();
                    string firmDocumentPath = string.Format(@"{0}\FirmInstitution\FI_{1}", Server.MapPath("~/uploads"), der.CustomerProspect.FirmInstitution.idFirmInstitution);
                    string destFullPath = ElectronicSafeDocumentBL.BuildClientUploadDocumentPath(docType, customer);
                    string filename = ElectronicSafeDocumentBL.BuildDocumentName(docType, der.idDer, false);

                    string destFILFilePath = System.IO.Path.Combine(destFullPath, filename);

                    //From firmModel or from upsideomodel
                    if (der.IsDerFromModel)
                    {
                        //Merge pdf
                        filename = der.CustomerProspect.FirmInstitution.LegalInformationFile;
                        string uploadedDoc = System.IO.Path.Combine(firmDocumentPath, filename);

                        if (System.IO.File.Exists(uploadedDoc))
                        {
                            Upsilab.Business.Configuration.FirmInstitutionPdfGeneration.GenerateDERByMerge(der.CustomerProspect.FirmInstitution, uploadedDoc, destFILFilePath, false, out pageCount);
                        }
                        else
                        {
                            error = LanguageData.GetContent("le_pdf_doc_entree_en_relation_n_existe_pas");
                        }

                    }
                    else
                    {
                        //From upsideo model => generate it
                        pageCount = Upsilab.Business.Configuration.FirmInstitutionPdfGeneration.GenerateDER(der.CustomerProspect.FirmInstitution, der.CustomerProspect.idCustomer, destFILFilePath, false);
                    }

                    if (!System.IO.File.Exists(destFILFilePath))
                    {
                        error = LanguageData.GetContent("le_pdf_doc_entree_en_relation_n_existe_pas");
                    }
                    else
                    {
                        //B- Prepare object to send to signature
                        signatureParameters = new SignatureParameters()
                        {
                            page = (pageCount > 0) ? pageCount : 16, //DER : 14pages
                            x_adviser = 33,
                            x_customer = 120,
                            y = 177
                        };

                        DocumentToSign docDER = new DocumentToSign()
                        {
                            Label = LanguageData.GetContent("doc_entree_en_relation"),
                            Description = LanguageData.GetContent("doc_entree_en_relation"),
                            PathFilename = destFILFilePath,
                            Type = DTPClient.DocumentTypes.CONTRACT.ToString(),
                            SignatureParameters = signatureParameters
                        };

                        documentsToSign.Add(docDER);
                    }

                    #endregion

                    #region 2- Presentation etablissement
                    if (der.AttachPresentation)
                    {
                        //A- PDF ?
                        pageCount = 0;
                        docType = ElectronicSafeDocumentBL.DocumentType.BS.ToString();
                        firmDocumentPath = string.Format(@"{0}\FirmInstitution\FI_{1}", Server.MapPath("~/uploads"), der.CustomerProspect.FirmInstitution.idFirmInstitution);
                        destFullPath = ElectronicSafeDocumentBL.BuildClientUploadDocumentPath(docType, customer);
                        filename = ElectronicSafeDocumentBL.BuildDocumentName(docType, der.idDer, false);

                        string destBSFilePath = System.IO.Path.Combine(destFullPath, filename);

                        //From firmModel or from upsideomodel
                        if (der.IsPresentationFromModel)
                        {
                            //Merge pdf
                            filename = der.CustomerProspect.FirmInstitution.PresentationFile;
                            string uploadedDoc = System.IO.Path.Combine(firmDocumentPath, filename);

                            if (System.IO.File.Exists(uploadedDoc))
                            {
                                Upsilab.Business.Configuration.FirmInstitutionPdfGeneration.GeneratePresentationByMerge(der.CustomerProspect.FirmInstitution, uploadedDoc, destBSFilePath, false, out pageCount);
                            }
                            else
                            {
                                error = LanguageData.GetContent("pdf_presentation_etab_n_existe_pas_ou");
                            }

                        }
                        else
                        {
                            //From upsideo model => generate it
                            pageCount = Upsilab.Business.Configuration.FirmInstitutionPdfGeneration.GeneratePresentation(der.CustomerProspect.FirmInstitution, destBSFilePath, false);
                        }

                        if (!System.IO.File.Exists(destBSFilePath))
                        {
                            error = LanguageData.GetContent("pdf_presentation_etab_n_existe_pas_ou");
                        }
                        else
                        {
                            //B- Prepare object to send to signature
                            signatureParameters = new SignatureParameters()
                            {
                                // page = (pageCount > 0) ? pageCount : 6, //BS : 6pages
                                page = pageCount,
                                x_adviser = 33,
                                x_customer = 120,
                                y = 177
                            };

                            DocumentToSign docPE = new DocumentToSign()
                            {
                                Label = LanguageData.GetContent("presentation_de_l_etab"),
                                Description = LanguageData.GetContent("presentation_de_l_etab"),
                                PathFilename = destBSFilePath,
                                Type = DTPClient.DocumentTypes.APPENDIX1.ToString(),
                                SignatureParameters = signatureParameters
                            };

                            documentsToSign.Add(docPE);
                        }
                    }
                    #endregion

                    //Signature
                    if (documentsToSign.Count == 0)
                    {
                        error = LanguageData.GetContent("aucun_doc_a_signer_veuillez");
                    }

                    if (string.IsNullOrEmpty(error))
                    {
                        // Sign the document mission
                        Upsilab.Data.Model.User userAdviser = (der.User != null) ? der.User : Upsilab.Business.Utility.SessionManager.GetUserSession();
                        urlIHM_Dictao = SignatureDocumentBL_4_1.SignDERByAdviser(der.idDer, documentsToSign, userAdviser);
                    }
                }
            }
            catch (Exception ex)
            {
                Upsilab.Business.Log.Log.AppendException(ex);
                error = ex.Message;
            }

            if (!string.IsNullOrEmpty(error))
            {
                SignatureModel signatureModel = new SignatureModel()
                {
                    H1Title = Business.Language.LanguageContentBL.Translate("der_title"),
                    HeadTitle = string.Format("Signature {0}", Business.Language.LanguageContentBL.Translate("der_title")),
                    ErrorMessage = error
                };

                return View("AllerSignature", signatureModel);
            }
            else
            {
                return Redirect(urlIHM_Dictao);
            }

        }
        private string BuildSignatureLog(DER der)
        {
            string signatureLog = string.Empty;

            //Conseiller name
            string userAdviserName = string.Empty;
            if (der.User != null)
            {
                userAdviserName = der.User.EntireName + "<br />";
            }

            if (der.Status == RegulatoryDocumentModel.Status.InProgress.ToString())
            {
                signatureLog = string.Empty;
            }
            else if (der.Status == RegulatoryDocumentModel.Status.WaitingForAdviserSignature.ToString())
            {
                //If not signed by adviser
                if (!der.SignedByCustomer)
                {
                    signatureLog = string.Format("<li>En attente signature Conseiller<br />{0}</li>", userAdviserName);
                }
                else
                {
                    //Already signed by the client
                    signatureLog = string.Format(@"<li>Signé par le Client<br />le {0}</li>
                                                   <li>En attente signature Conseiller<br />{1}</li>", der.DateCustomerSignature.Value.ToShortDateString(), userAdviserName);
                }
            }
            else if (der.Status == RegulatoryDocumentModel.Status.WaitingForClientSignature.ToString())
            {
                //If not signed by adviser
                if (!der.SignedByAdviser)
                {
                    signatureLog = "<li>En attente signature Client</li>";
                }
                else
                {
                    signatureLog = string.Format(@"<li>Signé par le Conseiller<br />{0}le {1}</li>
                                               <li>En attente signature Client</li>", userAdviserName, der.DateAdviserSignature.Value.ToShortDateString());
                }
            }
            else if (der.Status == RegulatoryDocumentModel.Status.Completed.ToString())
            {
                //Case signed manually
                if (!der.DateAdviserSignature.HasValue)
                {
                    signatureLog = "<li>Signé manuellement par <br /> le Conseiller et le Client </li>";
                }
                else
                {
                    string adviserText = string.Format(@"<li>Signé par le Conseiller<br />{0}le {1}</li>", userAdviserName, der.DateAdviserSignature.Value.ToShortDateString());
                    string clientText = string.Format(@"<li>Signé par le Client<br />le {0}</li>", der.DateCustomerSignature.Value.ToShortDateString());

                    if (DateTime.Compare(der.DateAdviserSignature.Value, der.DateCustomerSignature.Value) < 0) //Conseille signe en premier
                    {
                        signatureLog = string.Concat(adviserText, clientText);
                    }
                    else
                    {
                        signatureLog = string.Concat(clientText, adviserText);
                    }
                }
            }

            return signatureLog;

        }
        private DER CreateDer(DerModel derModel, RegulatoryDocumentModel.Status docStatus = RegulatoryDocumentModel.Status.Created)
        {
            DER der = new DER()
            {
                idDer = GuidHelper.GenerateGuid(),
                idCustomerProspect = derModel.TargetCustomerProspect.idCustomer,
                Status = docStatus.ToString(),
                DateCreated = DateTime.Now,
                DateUpdated = DateTime.Now,
                IsDerFromModel = true,
                AttachPresentation = true,
                IsPresentationFromModel = true
            };

            DerBL.InsertDER(der);

            return der;
        }
        public DerModel GetViewDataModel(Guid idTargetCustomer)
        {
            DerModel DERModel = new DerModel();
            DERModel.TargetCustomerProspect = CustomerProspectBL.GetCustomerProspectById(idTargetCustomer);

            //1- Get latest DER document for the customer or create if no doc
            DER der = DerBL.GetLatestDERByIdCustomer(idTargetCustomer);

            //2- If null, create one
            //If current user is END-USER, don't create new document
            var currentUser = SessionManager.GetUserSession();

            if (!currentUser.IsEndUser())
            {
                if (der == null)
                {
                    der = this.CreateDer(DERModel);
                    //update customer status                 
                    DERModel.TargetCustomerProspect.DerStatus = RegulatoryDocumentModel.Status.Created.ToString();
                    CustomerProspectBL.Update(DERModel.TargetCustomerProspect);
                }
                else if (der.Status == RegulatoryDocumentModel.Status.Canceled.ToString()
                         || der.Status == RegulatoryDocumentModel.Status.Completed.ToString())
                {
                    //3- Check if canceled or completed : create a new document in progress

                    //Update : #4535 / #4536 : always create an initial mission document => status = Created
                    der = this.CreateDer(DERModel);

                    //update customer 
                    DERModel.TargetCustomerProspect.DerStatus = RegulatoryDocumentModel.Status.Created.ToString();
                    CustomerProspectBL.Update(DERModel.TargetCustomerProspect);
                }
            }
            else
            {
                if (der == null)
                {
                    der = new DER();
                }
            }

            DERModel.Der = der;

            //4- Signature log
            DERModel.SignatureInformation = this.BuildSignatureLog(DERModel.Der);

            //5- Check credits
            DERModel.InsufficientCreditMessage = this.CheckInsufficientCredits(DERModel);

            //6- Signature controller
            DERModel.SignatureController = SignatureDocumentBL.GetSignatureControllerName(der.Status, der.idDTPUserAccess);

            return DERModel;
        }