public Appointments_attachedDTO GetFileName([FromBody] Appointments_attachedDTO value) { var query = NHibernateSession.QueryOver <Data.ControlCenter.Model.Appointments_attached>() .Where(de => de.FileName == value.FileName) .List(); IList <Models.Appointments_attachedDTO> cDTO = AutoMapper.Mapper.Map <IList <Data.ControlCenter.Model.Appointments_attached>, IList <Models.Appointments_attachedDTO> >(query); var Reg = new Models.Appointments_attachedDTO(); foreach (var item in cDTO) { Reg = item; break; } var ApiArchivo = new Class.UploadedFile(); Reg.Content = ApiArchivo.GetFile(value.FileName); return(Reg); }
public JsonResult AddAnexo(FormCollection frm) { var respuesta = new Models.ResponseDTO(); if (Request.Files.Count > 0) { HttpPostedFileBase uploadedFile = Request.Files[0]; if (!String.IsNullOrEmpty(uploadedFile.FileName)) { if (uploadedFile != null && uploadedFile.ContentLength > 0) { var FileExtension = Path.GetExtension(uploadedFile.FileName); var ContentType = uploadedFile.ContentType; var namefile = String.Empty; var FileUpload = new Models.Appointments_attachedDTO(); try { FileUpload.ContentType = ContentType; FileUpload.FileType = FileExtension; var array = new Byte[uploadedFile.ContentLength]; uploadedFile.InputStream.Position = 0; uploadedFile.InputStream.Read(array, 0, uploadedFile.ContentLength); FileUpload.Content = array; respuesta = new Class.UploadedFile().AddFile(FileUpload); //namefile = await Class.StorageService.Instance.UploadFile(uploadedFile.InputStream, FileExtension).; } catch (Exception ex) { respuesta.Message = ex.Message; } if (respuesta.Success == true) { Models.Appointments_attachedDTO newAttchment = new Models.Appointments_attachedDTO(); //newAttchment.UrlFile = "https://appbatzstorage.blob.core.windows.net/appbatzimages/" + namefile; newAttchment.FileName = respuesta.InternalKey; var IdApp_medical = (int)Session["IdApp_medical"]; newAttchment.IdApp_medical = IdApp_medical; newAttchment.Log = new Models.LogActualizacionDTO(); newAttchment.Log.UserCreation = (int)Session["IdUsuario"]; newAttchment.FileType = FileExtension; newAttchment.ContentType = ContentType; API.Appoint_attachedController ApiAnexo = new API.Appoint_attachedController(); respuesta = ApiAnexo.CrearRegistro(newAttchment); } } else { respuesta.Message = "Tamaño de archivo inválido"; } } else { respuesta.Message = "Nombre de archivo vacio"; } } else { respuesta.Message = "No existe un documento de adjunto"; } return(Json(respuesta, JsonRequestBehavior.AllowGet)); }