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)); } }
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)); } }
/// <summary> /// Runs the worker once to do the tests. /// </summary> public override void RunOnce() { // If this method is already running, then leave the already running alone, and return. // If it is not running, set the value os locker to 1 to indicate that now it is running. if (Interlocked.Exchange(ref locker, 1) != 0) { Trace.TraceInformation("TestWorker.RunOnce(): already running, exiting now."); return; } Trace.TraceInformation("TestWorker.RunOnce(): running service"); var utcNow = this.GetUtcNow(); using (var db = this.CreateNewCerebelloEntities()) { // trying to save to the database Exception exSaveToDb = null; SPECIAL_Test dbObj = null; try { var o = new SPECIAL_Test { CreatedOn = utcNow, }; db.SPECIAL_Test.AddObject(o); db.SaveChanges(); dbObj = o; } catch (Exception ex) { exSaveToDb = ex; } if (exSaveToDb == null) { Trace.TraceInformation("TestWorker.RunOnce(): DB object saved"); } // trying to save a file in the storage Exception exSaveToStorage = null; try { var storageManager = new WindowsAzureBlobStorageManager(); using (var stream = new MemoryStream(new byte[0])) storageManager.UploadFileToStorage( stream, "worker-test", string.Format("{0}", utcNow.ToString("yyyy'-'MM'-'dd hh'-'mm"))); } catch (Exception ex) { exSaveToStorage = ex; } if (exSaveToStorage == null) { Trace.TraceInformation("TestWorker.RunOnce(): blob saved to storage"); } // Sending e-mail about test status Exception exSendEmail = null; try { var obj = new Dictionary <string, Exception> { { "exSaveToDb", exSaveToDb }, { "exSaveToStorage", exSaveToStorage }, }; var mailMessage = this.CreateEmailMessage("TestEmail", new MailAddress("*****@*****.**"), obj); if (!this.TrySendEmail(mailMessage)) { throw new Exception("Cannot send e-mail message."); } } catch (Exception ex) { exSendEmail = ex; } if (exSendEmail == null) { Trace.TraceInformation("TestWorker.RunOnce(): e-mail message sent"); } // Save result to storage var fileText = new StringBuilder(1000); fileText.AppendLine("File saved from TestWorker"); if (exSaveToDb != null) { fileText.AppendLine(); fileText.AppendLine("Save to DB failed: " + exSaveToDb.Message); } if (exSaveToStorage != null) { fileText.AppendLine(); fileText.AppendLine("Save to Storage failed: " + exSaveToStorage.Message); } if (exSendEmail != null) { fileText.AppendLine(); fileText.AppendLine("Send e-mail failed: " + exSendEmail.Message); } if (exSaveToStorage == null) { try { var storageManager = new WindowsAzureBlobStorageManager(); using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(fileText.ToString()))) storageManager.UploadFileToStorage( stream, "worker-test", string.Format("{0}", utcNow.ToString("yyyy'-'MM'-'dd hh'-'mm"))); } catch { } } // Save result to db if (exSaveToDb == null) { try { if (dbObj != null) { dbObj.Value = fileText.ToString(); db.SaveChanges(); } } catch { } } } // setting locker value to 0 if (Interlocked.Exchange(ref locker, 0) != 1) { throw new Exception("The value of locker should be 1 before setting it to 0."); } }