gov.va.medora.mdws.SecureMessageLib.addAttachment C# (CSharp) Method

addAttachment() public method

public addAttachment ( string pwd, Int32 messageId, Int32 messageOplock, string fileName, string mimeType, byte attachment ) : AttachmentTO
pwd string
messageId System.Int32
messageOplock System.Int32
fileName string
mimeType string
attachment byte
return gov.va.medora.mdws.dto.sm.AttachmentTO
        public dto.sm.AttachmentTO addAttachment(string pwd, Int32 messageId, Int32 messageOplock, string fileName, string mimeType, byte[] attachment)
        {
            AttachmentTO result = new AttachmentTO();

            if (String.IsNullOrEmpty(pwd))
            {
                result.fault = new FaultTO("Missing pwd");
            }
            else if (messageId <= 0)
            {
                result.fault = new FaultTO("Invalid message ID");
            }
            else if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(mimeType) || attachment == null || attachment.Length <= 0)
            {
                result.fault = new FaultTO("Must supply all attachment properties");
            }

            if (result.fault != null)
            {
                return result;
            }

            try
            {
                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    AttachmentDao dao = new AttachmentDao(cxn);
                    MessageAttachment newAttachment = dao.attachToMessage(
                        new MessageAttachment() { AttachmentName = fileName, MimeType = mimeType, SmFile = attachment },
                        new Message() { Id = messageId, Oplock = messageOplock });
                    result = new AttachmentTO(newAttachment);
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return result;
        }