public ActionResult GetProfilePicture(int personId) { try { var person = this.db.Persons.First(p => p.Id == personId); if (person.PictureBlobName != null) { var storageManager = new WindowsAzureBlobStorageManager(); var picture = storageManager.DownloadFileFromStorage(Constants.PERSON_PROFILE_PICTURE_CONTAINER_NAME, person.PictureBlobName); return(this.File(picture, "image/png", person.PictureBlobName)); } // if the file does not exist, return a male or female image var pictureResource = Assembly.GetExecutingAssembly().GetManifestResourceStream( person.Gender == (int)TypeGender.Male ? "CerebelloWebRole.Resources.Male-Default-Profile.jpg" : "CerebelloWebRole.Resources.Female-Default-Profile.jpg"); return(pictureResource != null?this.File(pictureResource, "image/jpg") : null); } catch (Exception ex) { var pictureResource = Assembly.GetExecutingAssembly().GetManifestResourceStream("CerebelloWebRole.Resources.Male-Default-Profile.jpg"); return(pictureResource != null?this.File(pictureResource, "image/jpg") : null); } }
public ActionResult DownloadZipFile(int patientId) { var patient = this.db.Patients.First(p => p.Id == patientId); var zipMemoryStream = new MemoryStream(); using (var zip = new ZipFile()) { var patientFiles = this.db.PatientFiles.Where(pf => pf.PatientId == patientId).ToList(); var storageManager = new WindowsAzureBlobStorageManager(); foreach (var patientFile in patientFiles) { var fileStream = storageManager.DownloadFileFromStorage( patientFile.FileMetadata.ContainerName, patientFile.FileMetadata.BlobName); zip.AddEntry(patientFile.FileMetadata.SourceFileName, fileStream); } zip.Save(zipMemoryStream); } zipMemoryStream.Seek(0, SeekOrigin.Begin); return(this.File( zipMemoryStream, "application/zip", patient.Person.FullName + " - Arquivos - " + this.GetPracticeLocalNow().ToShortDateString() + ".zip")); }
public ActionResult DownloadAllPatientsZipFile() { var mainZipMemoryStream = new MemoryStream(); // there will an outer zip file that will contain an inner // zip file for each patient that has files using (var outerZip = new ZipFile()) { foreach (var patient in this.Doctor.Patients) { // if the patient has no files, he's not going to be included if (!patient.PatientFiles.Any()) { continue; } var innerZipMemoryStream = new MemoryStream(); using (var innerZip = new ZipFile()) { var storageManager = new WindowsAzureBlobStorageManager(); foreach (var patientFile in patient.PatientFiles) { try { var fileStream = storageManager.DownloadFileFromStorage( patientFile.FileMetadata.ContainerName, patientFile.FileMetadata.BlobName); innerZip.AddEntry(patientFile.FileMetadata.SourceFileName, fileStream); } catch (Exception ex) { // in this case the file exists in the database but does not exist in the storage. Trace.TraceError(ex.Message); } } innerZip.Save(innerZipMemoryStream); } innerZipMemoryStream.Seek(0, SeekOrigin.Begin); outerZip.AddEntry(patient.Person.FullName + ".zip", innerZipMemoryStream); } outerZip.Save(mainZipMemoryStream); } mainZipMemoryStream.Seek(0, SeekOrigin.Begin); return(this.File( mainZipMemoryStream, "application/zip", this.Doctor.Users.ElementAt(0).Person.FullName + " - Arquivos dos pacientes - " + this.GetPracticeLocalNow().ToShortDateString() + ".zip")); }