Пример #1
0
        /// <summary>
        /// Delete the patient with the given id.
        /// </summary>
        /// <param name="id">Id of the patient to delete.</param>
        /// <returns>bool indicating if the deletion was successful.</returns>
        public bool Delete(int id)
        {
            var exists = Repository.Patients.Any(p => p.Id == id);

            if (!exists)
            {
                return(false);
            }

            //Delete related NbrSurveillances
            var surveillances = _nbrSurveillanceService.FindByPatientId(id);

            surveillances.ForEach(s => _nbrSurveillanceService.Delete(s.Id));

            //Delete related Hypothermias
            var hypothermias = _hypothermiaService.FindByPatientId(id);

            hypothermias.ForEach(h => _hypothermiaService.Delete(h.Id));

            //Load related entities and delete patient
            var patient = new Patient {
                Id = id
            };

            Repository.Patients.Attach(patient);

            Repository.Entry(patient).Collection(p => p.Operations).Load();
            Repository.Patients.Remove(patient);

            Save();
            return(true);
        }
Пример #2
0
        public void Delete()
        {
            //Arrange
            var hypothermia = _dataContext.Hypothermias
                              .Include(h => h.CnsExploration)
                              .Include(h => h.Analysis)
                              .First();
            var hypothermiaId = hypothermia.Id;
            var explorationId = hypothermia.CnsExploration.Id;
            var analysisId    = hypothermia.Analysis.Id;

            //Act
            var deleted = _hypothermiaService.Delete(hypothermiaId);

            hypothermia = _hypothermiaService.FindById(hypothermiaId);
            var exploration = _dataContext.CnsExplorations.FirstOrDefault(e => e.Id == explorationId);
            var analysis    = _dataContext.Analyses.FirstOrDefault(a => a.Id == analysisId);

            //Assert
            Assert.That(deleted, Is.True);
            Assert.That(hypothermia, Is.Null);
            Assert.That(exploration, Is.Null);
            Assert.That(analysis, Is.Null);
        }
Пример #3
0
        public ActionResult Delete(int id, int fromId)
        {
            //Check that the tracking is not closed
            if (_patientService.IsClosed(fromId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var deleted = _hypothermiaService.Delete(id);

            //Delete failed because of a wrong id
            if (!deleted)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            _hypothermiaService.Log(OperationType.HypothermiaDelete, User.Identity.GetUserId <int>(),
                                    patientId: fromId, data: "HypothermiaID: " + id);
            return(RedirectToAction("View", "Hypothermia", new { id = fromId }));
        }