示例#1
0
        public void SaveVisualInspection(Guid documentId, bool approved, string comments, string userName)
        {
            AssociateDocument associateDocument = this.MomentaDb.AssociateDocuments.Single(d => d.DocumentId == documentId);

            if (associateDocument.ApprovedDate.HasValue != approved)
            {
                associateDocument.ApprovedDate = approved ? DateTime.Now : (DateTime?)null;
                associateDocument.ApprovedBy   = approved ? userName : null;
            }

            if (!string.IsNullOrEmpty(comments))
            {
                var comment = new AssociateDocumentComment
                {
                    DocumentId  = documentId,
                    CreatedTime = DateTime.Now,
                    Comment     = comments,
                    User        = userName
                };

                this.MomentaDb.AssociateDocumentComments.AddObject(comment);
            }

            this.MomentaDb.SaveChanges();
        }
示例#2
0
        public void ApproveDocument(Guid documentId, string userName, DateTime approvedDate)
        {
            AssociateDocument document = this.MomentaDb.AssociateDocuments.Single(d => d.DocumentId == documentId);

            document.ApprovedBy   = userName;
            document.ApprovedDate = approvedDate;

            this.MomentaDb.SaveChanges();
        }
示例#3
0
        public void SaveReferenceDocument(Guid documentId, int associateId, string filePath, int documentTypeId, int fileSize)
        {
            using (var scope = new TransactionScope(
                TransactionScopeOption.Required,
                new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
            {
                SqlCommand command = FileStreamHelper.GetCommandForDocumentUpsert(filePath, true, documentId);
                new FileStreamHelper().SaveDocumentWithoutFileStream(
                    command, ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, filePath);

                var associateDocumentLinkEntry = new AssociateDocument
                {
                    AssociateId = associateId,
                    DocumentId = documentId,
                    DocumentTypeId = documentTypeId,
                    FileSizes=fileSize
                };

                this.MomentaDb.AssociateDocuments.AddObject(associateDocumentLinkEntry);
                this.MomentaDb.SaveChanges();
                scope.Complete();
            }
        }
示例#4
0
        public void SaveCV(int associateId, string filePath, string edit)
        {
            using (var scope = new TransactionScope(
                TransactionScopeOption.Required,
                new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
            {

                SqlCommand command = GetCommandForCVUpload(associateId, filePath);
                new FileStreamHelper().SaveDocumentWithoutFileStream(
                    command, ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString, filePath);

                //add associate document
                var documentId = this.MomentaDb.CVs.Where(cv => cv.AssociateId == associateId).SingleOrDefault().Id;

                if (edit == null)
                {
                    edit = "";
                }

                if (!this.MomentaDb.AssociateDocuments.Where(cv => cv.DocumentId == documentId && cv.DocumentTypeId == (int)AssociateDocumentType.CV).Any() && !edit.Equals("Edit"))
                {
                    var associateDocumentLinkEntry = new AssociateDocument
                    {
                        AssociateId = associateId,
                        DocumentId = documentId,
                        DocumentTypeId = (int)AssociateDocumentType.CV,
                        CreatedDate = DateTime.Now
                    };

                    this.MomentaDb.AssociateDocuments.AddObject(associateDocumentLinkEntry);
                    this.MomentaDb.SaveChanges();
                }
                else
                {
                    var aDocs = this.MomentaDb.AssociateDocuments.Where(x => x.AssociateId == associateId && x.DocumentTypeId == (int)AssociateDocumentType.CV).ToList();
                    AssociateDocument old = aDocs.OrderByDescending(p => p.CreatedDate).FirstOrDefault();
                    //.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.CreatedDate = DateTime.Now;

                    this.MomentaDb.AssociateDocuments.AddObject(associateDocumentLinkEntry);
                    this.MomentaDb.AssociateDocuments.DeleteObject(old);

                    if (this.MomentaDb.AssociateDocumentComments.Where(x => x.DocumentId == oldId).Any())
                    {
                        var oldComment = this.MomentaDb.AssociateDocumentComments.Where(x => x.DocumentId == oldId).SingleOrDefault();
                        this.MomentaDb.AssociateDocumentComments.DeleteObject(oldComment);
                    }
                    this.MomentaDb.SaveChanges();

                    //Delete Orphan
                    //this.MomentaDb.DeleteDocument(oldId);
                }
                scope.Complete();

            }
        }
示例#5
0
        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();
            }
        }
示例#6
0
        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);
            // }
        }