public void SaveAssociatePDFDocument( AssociateDocumentType documentType, string documentTitle, Guid fileGuid, int associateId, byte[] fileData) { this.associateRepo.SaveAssociatePDFDocument(documentType, documentTitle, fileGuid, associateId, fileData); }
public bool GetDocumentVATApprovalStatus(AssociateDocumentType vatCertificate, int id) { return(associateRepo.GetDocumentVATApprovalStatus(vatCertificate, id)); }
public bool GetDocumentVATApprovalStatus(AssociateDocumentType vatCertificate, int id) { return associateRepo.GetDocumentVATApprovalStatus(vatCertificate, id); }
public void SaveAssociateDocument(AssociateDocumentType documentType, string documentTitle, Guid fileGuid, int associateId, string filePath, int fileSize, string edit) { this.associateRepo.SaveAssociateDocument(documentType, documentTitle, fileGuid, associateId, filePath, fileSize, edit); }
public Guid?GetLatestDocumentIdOfType(AssociateDocumentType value, int associateId) { return(this.associateRepo.GetLatestDocumentIdOfType(value, associateId)); }
public void SaveReferenceDocument(AssociateDocumentType documentType, Guid documentId, int associateId, string filePath, int fileSize) { this.associateRepo.SaveReferenceDocument(documentId, associateId, filePath, (int)documentType, fileSize); }
public ActionResult DownloadDocument(Guid? id, AssociateDocumentType? documentType, int? associateId) { try { if (documentType == AssociateDocumentType.CV && associateId.HasValue) { return this.DownloadCV(associateId.Value); } if (id.HasValue) { return this.DownloadDocument(id.Value, null, documentType != AssociateDocumentType.Photo); } return null; } catch (Exception ex) { ErrorSignal.FromCurrentContext().Raise(ex); this.ModelState.AddModelError( string.Empty, "An expect error has occcured. Unable to load document."); return null; } }
public Guid? GetLatestDocumentIdOfType(AssociateDocumentType documentType, int associateId) { AssociateDocument doc = this.MomentaDb.AssociateDocuments .OrderByDescending(d => d.CreatedDate) .FirstOrDefault(d => d.AssociateId == associateId && d.DocumentTypeId == (int)documentType); return doc == null ? (Guid?)null : doc.DocumentId; }
public bool GetDocumentVATApprovalStatus(AssociateDocumentType documentType, int associateId) { var doc = this.MomentaDb.AssociateDocuments .OrderByDescending(d => d.CreatedDate) .FirstOrDefault(d => d.AssociateId == associateId && d.DocumentTypeId == (int)documentType); return doc != null && doc.ApprovedDate != null; }
public void SaveAssociatePDFDocument(AssociateDocumentType documentType, string documentTitle, Guid documentId, int associateId, byte[] fileData) { string fileName; switch (documentType) { case AssociateDocumentType.DeclarationForm: fileName = "Declaration.pdf"; break; case AssociateDocumentType.InsuranceQuote: fileName = "InsuranceQuote.pdf"; break; case AssociateDocumentType.SelfBillingForm: fileName = "SelfBilling.pdf"; break; default: fileName = documentTitle ?? "Document.pdf"; break; } using (var scope = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { string userName; string applicationName; Audit.GetUserAndApplicationName(out applicationName, out userName); var command = new SqlCommand(@"dbo.InsertDocument_WithoutFileStreaming") { CommandType = CommandType.StoredProcedure }; command.Parameters.Add(new SqlParameter("@FileType", SqlDbType.VarChar, 10) { Value = ".pdf" }); command.Parameters.Add(new SqlParameter("@ContentType", SqlDbType.VarChar, 256) { Value = "application/pdf" }); command.Parameters.Add(new SqlParameter("@FileName", SqlDbType.VarChar, 256) { Value = fileName }); command.Parameters.Add(new SqlParameter("@UserName", SqlDbType.Char, 64) { Value = userName }); command.Parameters.Add(new SqlParameter("@ApplicationName", SqlDbType.Char, 64) { Value = applicationName }); command.Parameters.Add(new SqlParameter("@DocumentId", SqlDbType.UniqueIdentifier) { Value = documentId }); if (documentTitle != null) { command.Parameters.Add(new SqlParameter("@Title", SqlDbType.VarChar, 256) { Value = documentTitle }); } new FileStreamHelper().SaveDocumentWithoutFileStream( command, ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, fileData: fileData); var associateDocumentLinkEntry = new AssociateDocument { AssociateId = associateId, DocumentId = documentId, DocumentTypeId = (int)documentType }; this.MomentaDb.AssociateDocuments.AddObject(associateDocumentLinkEntry); this.MomentaDb.SaveChanges(); scope.Complete(); } }
public void SaveAssociateDocument(AssociateDocumentType documentType, string documentTitle, Guid documentId, int associateId, string filePath, int fileSize, string edit) { using (var scope = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { SqlCommand command = FileStreamHelper.GetCommandForDocumentUpsert(filePath, true, documentId); if (documentTitle != null) { command.Parameters.Add(new SqlParameter("@Title", SqlDbType.VarChar, 256) { Value = documentTitle }); } if (documentType == AssociateDocumentType.Photo) { Image newImage; using (Image image = Image.FromFile(filePath)) { newImage = ScaleImage(image, 110, 138); } byte[] photo; using (var ms = new MemoryStream()) { newImage.Save(ms, ImageFormat.Jpeg); photo = ms.ToArray(); } new FileStreamHelper().SaveDocumentWithoutFileStream( command, ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, null, photo); } else { new FileStreamHelper().SaveDocumentWithoutFileStream( command, ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, filePath); } if (edit == null) { edit = ""; } if (!edit.Equals("Edit")) { var associateDocumentLinkEntry = new AssociateDocument { AssociateId = associateId, DocumentId = documentId, DocumentTypeId = (int)documentType, CreatedDate = DateTime.Now, FileSizes = fileSize }; var placeHolder = this.MomentaDb.AssociateDocumentRequired.Where(x => x.AssociateId == associateId && x.DocumentTypeId == (int)documentType).SingleOrDefault(); if (placeHolder != null) { this.MomentaDb.AssociateDocumentRequired.DeleteObject(placeHolder); } this.MomentaDb.AssociateDocuments.AddObject(associateDocumentLinkEntry); this.MomentaDb.SaveChanges(); } else { var aDocs = this.MomentaDb.AssociateDocuments.Where(x => x.AssociateId == associateId && x.DocumentTypeId == (int)documentType).ToList(); AssociateDocument old = aDocs .GroupBy(p => p.DocumentTypeId) .Select(g => g.OrderByDescending(p => p.CreatedDate).FirstOrDefault()) .OrderByDescending(d => d.CreatedDate).SingleOrDefault(); Guid oldId = old.DocumentId; //update associate document var associateDocumentLinkEntry = new AssociateDocument(); associateDocumentLinkEntry.DocumentId = documentId; associateDocumentLinkEntry.AssociateId = old.AssociateId; associateDocumentLinkEntry.DocumentTypeId = old.DocumentTypeId; associateDocumentLinkEntry.FileSizes = old.FileSizes; associateDocumentLinkEntry.CreatedDate = old.CreatedDate; this.MomentaDb.AssociateDocuments.AddObject(associateDocumentLinkEntry); this.MomentaDb.AssociateDocuments.DeleteObject(old); //old.DocumentId = documentId; this.MomentaDb.SaveChanges(); //Delete Orphan this.MomentaDb.DeleteDocument(oldId); } scope.Complete(); } //// Declaration forms should always be obtained from DocuSign as a PDF so the following //// code should never be run. // if (documentType == AssociateDocumentType.DeclarationForm && !Path.GetExtension(filePath).IsEqualToCaseInsensitive(".pdf")) // { // string pdfPath = Path.ChangeExtension(filePath, ".pdf"); // ImageToPDF.CreatePDFFromImage(pdfPath, filePath); // this.SaveAssociateDocument(AssociateDocumentType.AutoConvertedDeclarationForm, documentId.ToString(), Guid.NewGuid(), associateId, pdfPath); // } }