Ejemplo n.º 1
0
        public ActionResult DeleteProfilePicture(int personId)
        {
            var person = this.db.Persons.FirstOrDefault(p => p.Id == personId);

            try
            {
                if (person != null && person.PictureBlobName != null)
                {
                    var storageManager = new WindowsAzureBlobStorageManager();
                    storageManager.DeleteFileFromStorage(Constants.PERSON_PROFILE_PICTURE_CONTAINER_NAME, person.PictureBlobName);
                    person.PictureBlobName = null;
                    this.db.SaveChanges();
                    return this.Json(
                        new
                            {
                                success = true
                            },
                        JsonRequestBehavior.AllowGet);
                }
                return this.Json(
                        new
                        {
                            success = true
                        },
                        JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.Json(
                    new
                    {
                        success = false,
                        message = ex.Message
                    }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 2
0
        public JsonResult Delete(int id)
        {
            try
            {
                var patient = this.db.Patients.First(m => m.Id == id);

                // delete anamneses manually
                var anamneses = patient.Anamneses.ToList();
                while (anamneses.Any())
                {
                    var anamnese = anamneses.First();
                    this.db.Anamnese.DeleteObject(anamnese);
                    anamneses.Remove(anamnese);
                }

                // delete diagnostic hipotheses manually
                var diagnosticHypotheses = patient.DiagnosticHypotheses.ToList();
                while (diagnosticHypotheses.Any())
                {
                    var diagnosticHypothesis = diagnosticHypotheses.First();
                    this.db.DiagnosticHypotheses.DeleteObject(diagnosticHypothesis);
                    diagnosticHypotheses.Remove(diagnosticHypothesis);
                }

                // delete receipts manually
                var receipts = patient.Receipts.ToList();
                while (receipts.Any())
                {
                    var receipt = receipts.First();
                    this.db.Receipts.DeleteObject(receipt);
                    receipts.Remove(receipt);
                }

                // delete physical exams requests manually
                var physicalExams = patient.PhysicalExaminations.ToList();
                while (physicalExams.Any())
                {
                    var physicalExam = physicalExams.First();
                    this.db.PhysicalExaminations.DeleteObject(physicalExam);
                    physicalExams.Remove(physicalExam);
                }

                // delete exam requests manually
                var examRequests = patient.ExaminationRequests.ToList();
                while (examRequests.Any())
                {
                    var examRequest = examRequests.First();
                    this.db.ExaminationRequests.DeleteObject(examRequest);
                    examRequests.Remove(examRequest);
                }

                // delete exam results manually
                var examResults = patient.ExaminationResults.ToList();
                while (examResults.Any())
                {
                    var examResult = examResults.First();
                    this.db.ExaminationResults.DeleteObject(examResult);
                    examResults.Remove(examResult);
                }

                // delete medical certificates manually
                var certificates = patient.MedicalCertificates.ToList();
                while (certificates.Any())
                {
                    var certificate = certificates.First();

                    // deletes fields within the certificate manually
                    while (certificate.Fields.Any())
                    {
                        var field = certificate.Fields.First();
                        this.db.MedicalCertificateFields.DeleteObject(field);
                    }

                    this.db.MedicalCertificates.DeleteObject(certificate);
                    certificates.Remove(certificate);
                }

                // delete diagnosis manually
                var diagnosis = patient.Diagnoses.ToList();
                while (diagnosis.Any())
                {
                    var diag = diagnosis.First();
                    this.db.Diagnoses.DeleteObject(diag);
                    diagnosis.Remove(diag);
                }

                // delete appointments manually
                var appointments = patient.Appointments.ToList();
                while (appointments.Any())
                {
                    var appointment = appointments.First();
                    this.db.Appointments.DeleteObject(appointment);
                    appointments.Remove(appointment);
                }

                // delete files manually
                var patientFiles = patient.PatientFiles.ToList();
                while (patientFiles.Any())
                {
                    var patientFile = patientFiles.First();
                    var file = patientFile.FileMetadata;

                    var storage = new WindowsAzureBlobStorageManager();
                    storage.DeleteFileFromStorage(Constants.AZURE_STORAGE_PATIENT_FILES_CONTAINER_NAME, file.SourceFileName);

                    this.db.PatientFiles.DeleteObject(patientFile);
                    this.db.FileMetadatas.DeleteObject(file);

                    patientFiles.Remove(patientFile);
                }

                // delete file groups manually
                var patientFileGroups = patient.PatientFileGroups.ToList();
                while (patientFileGroups.Any())
                {
                    var patientFileGroup = patientFileGroups.First();
                    this.db.PatientFileGroups.DeleteObject(patientFileGroup);
                    patientFileGroups.Remove(patientFileGroup);
                }

                this.db.Patients.DeleteObject(patient);
                this.db.SaveChanges();
                return this.Json(new JsonDeleteMessage { success = true }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.Json(new JsonDeleteMessage { success = false, text = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets a person picture as the specified tempFileName.
        /// The tempFileName will be COPIED from the "temp" Azure Storage container name
        /// tempFileName can be deleted afterwards
        /// </summary>
        /// <param name="personId"></param>
        /// <param name="tempFileName"></param>
        /// <returns></returns>
        public JsonResult TransferPersonPictureFromTempContainer(int personId, string tempFileName)
        {
            try
            {
                var person = this.db.Persons.First(p => p.Id == personId);
                var profilePictureBlobName = "profile_picture_" + personId;

                var sourceLocation = new BlobLocation(Constants.AZURE_STORAGE_TEMP_FILES_CONTAINER_NAME, tempFileName);
                var destinationLocation = new BlobLocation(Constants.PERSON_PROFILE_PICTURE_CONTAINER_NAME, profilePictureBlobName);

                // download temp file
                var storageManager = new WindowsAzureBlobStorageManager();
                //var tempFile = storageManager.DownloadFileFromStorage(sourceLocation);

                // if person has a profile picture already, delete it
                if (person.PictureBlobName != null)
                    storageManager.DeleteFileFromStorage(destinationLocation);

                storageManager.CopyStoredFile(sourceLocation, destinationLocation);

                // upload downloaded temp file to person profile
                //storageManager.UploadFileToStorage(tempFile, Constants.PERSON_PROFILE_PICTURE_CONTAINER_NAME, profilePictureBlobName);
                person.PictureBlobName = profilePictureBlobName;

                // delete temp file
                storageManager.DeleteFileFromStorage(sourceLocation);

                // this controller shouldn't know about patients but.. it's the easiest way to do this now
                if (person.Patients.Any())
                    person.Patients.First().IsBackedUp = false;

                this.db.SaveChanges();

                return this.Json(
                    new
                    {
                        success = true
                    }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return this.Json(
                    new
                    {
                        success = false,
                        message = ex.Message
                    }, JsonRequestBehavior.AllowGet);
            }
        }