예제 #1
0
        public ActionResult AddPatient(Patient patient)
        {
            context.Patients.Add(patient);
            context.SaveChanges();

            return(Ok());
        }
        public Guid AddPatient(Patient patient)
        {
            var patientRecord = _mapper.Map <PatientRecord>(patient);

            patientRecord.Id = Guid.NewGuid();
            patientRecord.RecordCreationDate = DateTime.UtcNow;
            _dbContext.Add(patientRecord);
            _dbContext.SaveChanges();
            return(patientRecord.Id);
        }
예제 #3
0
        public int DeleteEvent(int eventID)
        {
            var v = _context.CalendarEvents.Where(a => a.EventID == eventID).FirstOrDefault();

            if (v != null)
            {
                _context.CalendarEvents.Remove(v);
                return(_context.SaveChanges());
            }
            return(0);
        }
        public ActionResult Edit(PatientsEditModel model, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                using (var db = new PatientsDbContext())
                {
                    var patient = db.Patients.Find(model.Id);

                    if (patient == null || !IsAuthorizedToEdit(patient))
                    {
                        return(HttpNotFound());
                    }

                    patient.Id        = model.Id;
                    patient.Name      = model.Name;
                    patient.ImagePath = model.ImagePath;
                    patient.Room      = model.Room;
                    patient.Age       = model.Age;
                    patient.Status    = model.Status;
                    patient.Gender    = model.Gender;
                    patient.Condition = model.Condition;

                    if (image != null)
                    {
                        var allowedContentTypes = new[] { "image/jpeg", "image/jpg", "image/png" };

                        if (allowedContentTypes.Contains(image.ContentType))
                        {
                            var imagesPath = "/Content/Images/";

                            var fileName     = image.FileName;
                            var uploadPath   = imagesPath + fileName;
                            var physicalPath = Server.MapPath(uploadPath);

                            image.SaveAs(physicalPath);
                            patient.ImagePath = uploadPath;
                        }
                    }

                    db.SaveChanges();
                }

                return(RedirectToAction("Details", new { id = model.Id }));
            }
            return(View(model));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            using (var db = new PatientsDbContext())
            {
                var patient = db.Patients.Find(id);



                if (patient == null || !IsAuthorizedToEdit(patient))
                {
                    return(HttpNotFound());
                }
                db.Patients.Remove(patient);
                db.SaveChanges();
                return(RedirectToAction("AllPatients"));
            }
        }
        public ActionResult Create(CreateNewPatient model, HttpPostedFileBase image)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var doctorId = this.User.Identity.GetUserId();
                var patient  = new Patient
                {
                    Name      = model.Name,
                    Age       = model.Age,
                    Gender    = model.Gender,
                    Condition = model.Condition,
                    Status    = model.Status,
                    Room      = model.Room,
                    DoctorId  = doctorId,
                    Id        = model.Id
                };

                if (image != null)
                {
                    var allowedContentTypes = new[] { "image/jpeg", "image/jpg", "image/png" };

                    if (allowedContentTypes.Contains(image.ContentType))
                    {
                        var imagesPath = "/Content/Images/";

                        var fileName     = image.FileName;
                        var uploadPath   = imagesPath + fileName;
                        var physicalPath = Server.MapPath(uploadPath);

                        image.SaveAs(physicalPath);
                        patient.ImagePath = uploadPath;
                    }
                }
                var db = new PatientsDbContext();
                db.Patients.Add(patient);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = patient.Id }));
            }
            return(View(model));
        }
예제 #7
0
        public void Setup()
        {
            var options = new DbContextOptionsBuilder <PatientsDbContext>()
                          .UseInMemoryDatabase(databaseName: "PatientsDatabase")
                          .Options;

            _memoryDbContext = new PatientsDbContext(options);
            _memoryDbContext.Patients.Add(new PatientRecord()
            {
                Id = Guid.NewGuid()
            });
            _memoryDbContext.SaveChanges();
            _storageHandlerMock = new Mock <IStorageHandler>();
            _mockSettings       = new Mock <IOptions <Settings> >();
            _mapperMock         = new Mock <IMapper>();
            _mockSettings.Setup(x => x.Value).Returns(new Settings()
            {
                AppSettings = new AppSettings()
            });
            _storageHandlerMock.Setup(x => x.StoreFile(It.IsAny <Stream>())).Returns("path");
            _patientService = new PatientsService(_storageHandlerMock.Object, _mapperMock.Object, _mockSettings.Object, _memoryDbContext);
        }
예제 #8
0
 public int SaveChanges()
 {
     return(_context.SaveChanges());
 }