Esempio n. 1
0
 public SortAttachmentObject SaveSortAttachment(SortAttachmentObject sortAttachment)
 {
     if (sortAttachment.SortAttachmentId > 0) // Update
     {
         string sql = @"
             UPDATE  dat_SortAttachment
             SET     SortMainId = @SortMainId,
                     UploadDate = @UploadDate,
                     UploadEmployeeId = @UploadEmployeeId,
                     FileName = @FileName,
                     Note = @Note,
                     IsDeleted = @IsDeleted,
                     DeletedByEmployeeId = @DeletedByEmployeeId,
                     DeletedDate = @DeletedDate,
                     AttachmentType = @AttachmentType,
                     Size = @Size
             WHERE   SortAttachmentId = @SortAttachmentId";
         Config.Conn.Execute(sql, sortAttachment);
     }
     else
     {
         string sql = @"
             INSERT INTO dat_SortAttachment (
                 SortMainId,
                 UploadDate,
                 UploadEmployeeId,
                 FileName,
                 Note,
                 IsDeleted,
                 DeletedByEmployeeId,
                 DeletedDate,
                 AttachmentType,
                 Size
             )
             VALUES (
                 @SortMainId,
                 @UploadDate,
                 @UploadEmployeeId,
                 @FileName,
                 @Note,
                 @IsDeleted,
                 @DeletedByEmployeeId,
                 @DeletedDate,
                 @AttachmentType,
                 @Size
             )
             SELECT CAST(SCOPE_IDENTITY() AS INT)";
         sortAttachment.SortAttachmentId = Config.Conn.Query <int>(sql, sortAttachment).Single();
     }
     return(sortAttachment);
 }
Esempio n. 2
0
 public bool Delete(SortAttachmentObject sortAttachment)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_SortAttachmentFile WHERE SortAttachmentId = @SortAttachmentId", sortAttachment);
         Config.Conn.Execute("DELETE FROM dat_SortAttachment WHERE SortAttachmentId = @SortAttachmentId", sortAttachment);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("SortAttachmentObject::Delete", ex);
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
        public static SortAttachmentObject AddAttachment(int sortMainId, string fileName, string description, AttachmentTypeEnum attachmentType, int?size)
        {
            var sao = new SortAttachmentObject()
            {
                SortMainId         = sortMainId,
                FileName           = fileName,
                Note               = description,
                AttachmentTypeEnum = attachmentType,
                IsDeleted          = false,
                Size               = CalcSize(size)
            };

            sao.Save();

            return(sao);
        }
Esempio n. 4
0
        //public static SortAttachmentObject AddAttachment(int sortMainId, string fileName, string description, AttachmentTypeEnum attachmentType, int? size, byte[] contents)
        //{
        //    var sao = AddAttachment(sortMainId, fileName, description, attachmentType, size);
        //    repo.UploadFile(sao.SortAttachmentId, contents);

        //    return sao;
        //}

        public static SortAttachmentObject AddOstiAttachment(int sortMainId, string fileName, string employeeId, int?size, byte[] contents)
        {
            // There can be only one, so check to see if there already is one. If so, mark it as deleted.
            GetOstiAttachment(sortMainId)?.PerminateDelete();
            // Now add in a new one.
            var sao = new SortAttachmentObject()
            {
                SortMainId       = sortMainId,
                FileName         = fileName,
                Note             = "Transformed Final Document with cover sheet ready for OSTI",
                AttachmentType   = "OstiDoc",
                UploadEmployeeId = employeeId,
                IsDeleted        = false,
                Size             = "Unknown"
            };

            sao.Save(false);
            repo.UploadFile(sao.SortAttachmentId, contents);

            return(sao);
        }
Esempio n. 5
0
        private static bool UploadFilesFtpS(int sortMainId, string ostiId, ref string error)
        {
            bool uploaded = false;

            //// https://github.com/hgupta9/FluentFTP
            try
            {
                var file = SortAttachmentObject.GetOstiAttachment(sortMainId);
                if (file != null)
                {
                    using (FtpClient client = new FtpClient(Config.OstiFtpSite, Config.OstiFtpPort, Config.OstiFtpUsername, Config.OstiFtpPassword))
                    {
                        client.EncryptionMode       = FtpEncryptionMode.Explicit;
                        client.SslProtocols         = SslProtocols.Tls12;
                        client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
                        client.Connect();

                        if (client.IsConnected)
                        {
                            string fileName = $"{ostiId}{Path.GetExtension(file.FileName)}";
                            Stream stream   = file.Contents;
                            stream.Seek(0, SeekOrigin.Begin);

                            uploaded = client.Upload(stream, $"{Config.OstiFtpDirectory}{fileName}");

                            client.Disconnect();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogObject.LogError("OstiUploadObject::UploadFilesFtpS", ex);
                error = ex.Message;
            }

            return(uploaded);
        }