private void SaveSignedDocumentToServer(SignatureTransaction signatureTransaction, CoffreFortViewModel coffreViewModel, HttpPostedFileBase uploadedFile) { var lstDateSignatureObjects = new List<DateSignatureObjet>(); //CGP if (!string.IsNullOrEmpty(coffreViewModel.DateSignatureCGP)) { var dateSignature = new DateSignatureObjet() { Role = SignatoryBL.Roles.CGP.ToString(), DateSignature = Convert.ToDateTime(coffreViewModel.DateSignatureCGP) }; lstDateSignatureObjects.Add(dateSignature); } //Titulaire 1 if (!string.IsNullOrEmpty(coffreViewModel.DateSignatureTitulaire1)) { var dateSignature = new DateSignatureObjet() { Role = SignatoryBL.Roles.TITULAIRE1.ToString(), DateSignature = Convert.ToDateTime(coffreViewModel.DateSignatureTitulaire1) }; lstDateSignatureObjects.Add(dateSignature); } //Titulaire 2 if (!string.IsNullOrEmpty(coffreViewModel.DateSignatureTitulaire2)) { var dateSignature = new DateSignatureObjet() { Role = SignatoryBL.Roles.TITULAIRE2.ToString(), DateSignature = Convert.ToDateTime(coffreViewModel.DateSignatureTitulaire2) }; lstDateSignatureObjects.Add(dateSignature); } if (uploadedFile != null && uploadedFile.ContentLength > 0) { var fileName = System.IO.Path.GetFileName(uploadedFile.FileName); var documentRelativePath = string.Empty; var ext = Path.GetExtension(uploadedFile.FileName); var documentFullPath = ElectronicSafeDocumentBL.BuildSubscriptionFileDocumentsPath(coffreViewModel.IdSubscriptionFile, true, out documentRelativePath); var filename = ElectronicSafeDocumentBL.BuildDocumentNameWithExtension(ElectronicSafeDocumentBL.DocumentType.SF.ToString(), coffreViewModel.IdSubscriptionFile.ToString("D8"), ext); // 1- Sauvegarde dans le repertoire // documentFullPath = documentFullPath.Replace(@"fournisseur\uploads", @"user\uploads"); string filePath = System.IO.Path.Combine(documentFullPath, filename); uploadedFile.SaveAs(filePath); // 2- Sauvegarde dans la base données de données // 2-a- table "Document" var document = DocumentBL.GetDocumentByIdSignatureTransaction(signatureTransaction.idSignatureTransaction, ElectronicSafeDocumentBL.DocumentType.SF.ToString()); document.Location = documentRelativePath; document.Name = filename; DocumentBL.UpdateDocument(document); // 2-b- table "SignatureTransaction" signatureTransaction.Status = DocumentBL.Status.Saved.ToString(); signatureTransaction.DateSignaturesObjet = lstDateSignatureObjects.DateSignatureObjectToJson(); SignatureTransactionBL.UpdateSignatureTransaction(signatureTransaction); } }
public PartialViewResult OpenCoffreFort() { var dossierVm = new DossierViewModel(); SessionManager.Get<DossierViewModel>(KEY_DOSSIER, out dossierVm); //TODO : check dossierVm null DocumentType documentType = DocumentTypeBL.GetDocumentTypeByCode(ElectronicSafeDocumentBL.DocumentType.SF.ToString()); /* SF */ var sub = FrDossierBL.GetInfoLiteById(dossierVm.IdSubscriptionFile); /* */ Document doc = DocumentBL.GetDocumentByIdSignatureTransaction(sub.IdSignatureTransaction, ElectronicSafeDocumentBL.DocumentType.SF.ToString()); var coffreFortViewModel = new CoffreFortViewModel() { IdSubscriptionFile = dossierVm.IdSubscriptionFile, IdDocumentType = documentType.idDocumentType, DateSignatureCGP = DateTime.Now.ToShortDateString(), DateSignatureTitulaire1 = DateTime.Now.ToShortDateString(), DateSignatureTitulaire2 = DateTime.Now.ToShortDateString(), Document = doc }; return PartialView("UploadDocumentPopup", coffreFortViewModel); }
public ActionResult SaveSignedDocument(CoffreFortViewModel coffreViewModel, HttpPostedFileBase uploadedFile) { bool doSave = false; bool sendToCoffre = false; string error = string.Empty; var signatureTransaction = FrDossierBL.GetSignatureTransaction(coffreViewModel.IdSubscriptionFile); try { //Le CGP peut enregistrer un dossier signé //Le FOURNISSEUR peut enregistrer un dossier si pas encore enregistré par le CGP //Le FOURNISSEUR peut mettre au coffre le dossier enregistré //CGP ou FOURNISSEUR var currentUser = SessionManager.GetUserSession(); if (currentUser.IsProvider()) //Fournisseur { if (signatureTransaction.Status != DocumentBL.Status.Saved.ToString()) { doSave = true; sendToCoffre = true; } } else //CGP { doSave = true; } //Save document to server if (doSave) { SaveSignedDocumentToServer(signatureTransaction, coffreViewModel, uploadedFile); } //Send document to coffre fort if (sendToCoffre) { SaveSignedDocumentToCoffreFort(signatureTransaction.idSignatureTransaction, coffreViewModel.IdSubscriptionFile); } } catch (Exception ex) { error = ex.Message; Business.Log.Log.AppendException(ex); } if (!string.IsNullOrEmpty(error)) { TempData["CoffreFortError"] = error; } return RedirectToAction("BackFromCoffreFort"); //TODO }