public dto.sm.AttachmentTO addAttachment(string pwd, Int32 messageId, Int32 messageOplock, string fileName, string mimeType, AttachmentTO attachment) { AttachmentTO result = new AttachmentTO(); pwd = getConnectionString(pwd); if (String.IsNullOrEmpty(pwd)) { result.fault = new FaultTO("No connection string specified or configured"); } else if (messageId <= 0) { result.fault = new FaultTO("Invalid message ID"); } else if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(mimeType) || attachment == null || attachment.attachment == null || attachment.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.attachment }, new Message() { Id = messageId, Oplock = messageOplock }); result = new AttachmentTO(newAttachment); } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
public IActionResult EditPatient(string patientId) { Patient patient = new PatientDao().GetAllPatient().Where(x => x.PatientID == Convert.ToInt32(patientId)).ToList()[0]; List <Gender> lstGender = new GenderDao().GetAllGender().ToList(); lstGender.Insert(0, new Gender() { GenderID = 0, GenderName = "Select Gender Name" }); ViewBag.GenderList = new SelectList(lstGender, "GenderID", "GenderName"); List <Attachments> lstAttachments = new AttachmentDao().GetAllTmpAttachmentsByIssueId(Convert.ToInt32(patientId)).ToList(); ViewBag.AttachmentsList = lstAttachments; return(View(patient)); }
public dto.sm.AttachmentTO updateAttachment(string pwd, Int32 attachmentId, Int32 attachmentOplock, string fileName, string mimeType, AttachmentTO newAttachment) { AttachmentTO result = new AttachmentTO(); pwd = getConnectionString(pwd); if (String.IsNullOrEmpty(pwd)) { result.fault = new FaultTO("No connection string specified or configured"); } else if (attachmentId <= 0) { result.fault = new FaultTO("Invalid attachment ID"); } else if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(mimeType) || newAttachment == null || newAttachment.attachment == null || newAttachment.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 updatedAttachment = dao.updateAttachment(new MessageAttachment() { Id = attachmentId, Oplock = attachmentOplock, AttachmentName = fileName, MimeType = mimeType, SmFile = newAttachment.attachment }); updatedAttachment.SmFile = null; // don't pass back - client already has image so save the bandwidth result = new AttachmentTO(updatedAttachment); } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
public dto.sm.MessageTO deleteAttachment(string pwd, Int32 messageId) { MessageTO result = new MessageTO(); pwd = getConnectionString(pwd); if (String.IsNullOrEmpty(pwd)) { result.fault = new FaultTO("No connection string specified or configured"); } else if (messageId <= 0) { result.fault = new FaultTO("Invalid message ID"); } if (result.fault != null) { return(result); } try { using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { AttachmentDao dao = new AttachmentDao(cxn); Message dbMsg = dao.deleteAttachmentFromMessage(messageId); result = new MessageTO(dbMsg); } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
public dto.sm.AttachmentTO getAttachment(string pwd, Int32 attachmentId) { AttachmentTO result = new AttachmentTO(); pwd = getConnectionString(pwd); if (String.IsNullOrEmpty(pwd)) { result.fault = new FaultTO("No connection string specified or configured"); } else if (attachmentId <= 0) { result.fault = new FaultTO("Invalid attachment ID"); } if (result.fault != null) { return(result); } try { using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd })) { AttachmentDao dao = new AttachmentDao(cxn); MessageAttachment attachment = dao.getAttachment(attachmentId); result = new AttachmentTO(attachment); } } catch (Exception exc) { result.fault = new FaultTO(exc); } return(result); }
public JsonResult UploadFile(IFormFile attachFile) { ReturnMessage returnMessage = new ReturnMessage(); FindPatient fnPatient = new FindPatient(); if (attachFile == null) { fnPatient.RetCode = 0; fnPatient.RetMessage = "Please select one file!"; return(Json(fnPatient)); } try { List <FtpServer> lstFtpServer = new FtpServerDao().GetAllFtpServerList().ToList(); if (lstFtpServer == null || lstFtpServer.Count < 1) { fnPatient.RetCode = 0; fnPatient.RetMessage = "Can not connect FTP Server!"; return(Json(fnPatient)); } string serverAddress = lstFtpServer[0].ServerAddress; string userName = lstFtpServer[0].UserName; string password = lstFtpServer[0].Password; var ftpRequest = (FtpWebRequest)FtpWebRequest.Create(serverAddress + "FTPTEST.txt"); ftpRequest.Credentials = new NetworkCredential(userName, password); ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile; var ftpResponse = (FtpWebResponse)ftpRequest.GetResponse(); var ftpStream = ftpResponse.GetResponseStream(); Attachments attachment = new Attachments(); attachment.FileCode = ""; attachment.FileName = attachFile.FileName; int dotIndex = attachFile.FileName.LastIndexOf('.'); attachment.FileType = attachFile.FileName.Substring(dotIndex + 1); //User user = (User)Session["AppUser"]; attachment.AttachedBy = 1; //List<Attachments> lstAttachments = (List<Attachments>)Session["lstAttachments"]; List <Attachments> lstAttachments = new List <Attachments>(); returnMessage = new AttachmentDao().Create(attachment); if (returnMessage.RetCode > 0) { var attachFileName = returnMessage.RetMessage + "." + attachment.FileType; //var reader = new StreamReader(); Stream streamObj = attachFile.OpenReadStream(); byte[] buffer = new byte[attachFile.Length]; streamObj.Read(buffer, 0, buffer.Length); streamObj.Close(); streamObj = null; string ftpurl = String.Format("{0}/{1}", serverAddress, attachFileName); var requestObj = FtpWebRequest.Create(ftpurl) as FtpWebRequest; requestObj.Method = WebRequestMethods.Ftp.UploadFile; requestObj.Credentials = new NetworkCredential(userName, password); var requestStream = requestObj.GetRequestStream(); requestStream.Write(buffer, 0, buffer.Length); requestStream.Flush(); requestStream.Close(); requestObj = null; attachment.Id = returnMessage.RetCode; attachment.FileCode = returnMessage.RetMessage; fnPatient.RetCode = 1; lstAttachments.Add(attachment); } HttpContext.Session.SetObjectAsJson("lstAttachments", lstAttachments); fnPatient.AttachmentsList = lstAttachments; return(Json(fnPatient)); } catch (Exception ex) { fnPatient.RetCode = 0; fnPatient.RetMessage = "Error in file attachment"; return(Json(fnPatient)); } }