public async Task <IActionResult> Create(Int32?doctorId, DoctorPatientsCreateViewModel model)
        {
            if (doctorId == null)
            {
                return(this.NotFound());
            }

            var doctor = await this._context.Doctors
                         .SingleOrDefaultAsync(x => x.Id == doctorId);

            if (doctorId == null)
            {
                return(this.NotFound());
            }

            if (ModelState.IsValid)
            {
                var doctorPatient = new DoctorPatient
                {
                    DoctorId  = doctor.Id,
                    PatientId = model.PatientId
                };

                _context.Add(doctorPatient);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { doctorId = doctor.Id }));
            }
            this.ViewBag.Doctor   = doctor;
            ViewData["PatientId"] = new SelectList(_context.Patients, "Id", "Name", model.PatientId);
            return(this.View(model));
        }
        public void TC006()
        {
            //preconditions
            Doctor doctor = new Doctor();

            doctor.username = "******";
            doctor.password = "******";
            Database.createUser(doctor);

            Patient patient = new Patient();

            patient.name = "Sergio";
            patient.DoB  = "Jul";
            Database.createPatient(patient);

            DoctorPatient doctorPatient = new DoctorPatient();

            doctorPatient.patient_id = patient.id;
            doctorPatient.doctor     = "Alan";
            Database.createDoctorPatient(doctorPatient);

            //Execute
            var list = Database.getPatientList("Alan");

            //assert
            Assert.True(list.Count > 0);
        }
Пример #3
0
        public ActionResult DeleteDoctor(int joinId)
        {
            DoctorPatient joinEntry = _db.DoctorPatient.FirstOrDefault(entry => entry.DoctorPatientId == joinId);

            _db.DoctorPatient.Remove(joinEntry);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
        public ActionResult RemovePatient(int DoctorPatientId)
        {
            DoctorPatient joinEntry = _db.DoctorPatient.FirstOrDefault(x => x.DoctorPatientId == DoctorPatientId);

            _db.DoctorPatient.Remove(joinEntry);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void TC003()
        {
            //preconditions
            DoctorPatient doctorPatient = new DoctorPatient();

            doctorPatient.patient_id = 1;
            doctorPatient.doctor     = "Alan";

            //execute
            bool created = Database.createDoctorPatient(doctorPatient);

            //assert
            Assert.True(created == true);
        }
        public void TC004()
        {
            //preconditions
            DoctorPatient doctorPatient1 = new DoctorPatient();

            doctorPatient1.patient_id = 1;
            doctorPatient1.doctor     = "Alan";
            DoctorPatient doctorPatient2 = new DoctorPatient();

            doctorPatient2.patient_id = 1;
            doctorPatient2.doctor     = "Alan";

            //execute
            bool created1 = Database.createDoctorPatient(doctorPatient1);
            bool created2 = Database.createDoctorPatient(doctorPatient2);

            //assert
            Assert.True(created1 == true && created2 == false);
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("PatientId,FirstName,LastName,StreetAddress,PhoneNumber,Age,Sex")] Patient patient)
        {
            if (ModelState.IsValid)
            {
                // Get the current user
                var user = await GetCurrentUserAsync();

                _context.Add(patient);
                DoctorPatient newPatient = new DoctorPatient();
                newPatient.DoctorId  = user.Id;
                newPatient.PatientId = patient.PatientId;
                _context.Add(newPatient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(patient));
        }
        public async Task<IActionResult> Create(Int32? doctorId, DoctorPatientCreateModel model)
        {
            if (doctorId == null)
            {
                return this.NotFound();
            }

            var doctor = await this.context.Doctors
                .SingleOrDefaultAsync(x => x.Id == doctorId);

            if (doctor == null)
            {
                return this.NotFound();
            }

            if (DoctorPatientExists(doctor.Id, model.PatientId))
            {
                this.ModelState.AddModelError("PatientId", "This patient is already attached to this doctor");
                this.ViewBag.Doctor = doctor;
                this.ViewData["PatientId"] = new SelectList(this.context.Patients, "Id", "Name", model.PatientId);
                return this.View(model);
            }

            if (this.ModelState.IsValid)
            {
                var doctorPatient = new DoctorPatient
                {
                    DoctorId = doctor.Id,
                    PatientId = model.PatientId
                };

                this.context.Add(doctorPatient);
                await this.context.SaveChangesAsync();
                return this.RedirectToAction("Index", new { doctorId = doctor.Id });
            }

            this.ViewBag.Doctor = doctor;
            this.ViewData["PatientId"] = new SelectList(this.context.Doctors, "Id", "Name", model.PatientId);
            return this.View(model);
        }