Exemplo n.º 1
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var doctor = doctorData.GetDoctorById(Patient.DoctorId);
                Patient.Doctor = doctor;
                if (Patient.Id == 0)
                {
                    Patient = patientData.Create(Patient);
                    TempData["TempMessage"] = "New patient is created!";
                }
                else
                {
                    Patient = patientData.Update(Patient);
                    TempData["TempMessage"] = "Data for patient is updated!";
                }

                patientData.Commit();
                return(RedirectToPage("./List"));
            }

            var doctors = doctorData.GetDoctors().ToList().Select(d => new { Id = d.Id, Display = $"{d.FirstName} {d.LastName}" });

            Doctors = new SelectList(doctors, "Id", "Display");
            Gender  = htmlHelper.GetEnumSelectList <Gender>();
            return(Page());
        }
        public IActionResult Update(PatientDto patientDto, int id)
        {
            var patient = patientData.GetPatientById(id);

            patient.Age       = patientDto.Age;
            patient.City      = patientDto.City;
            patient.DoctorId  = patientDto.DoctorId;
            patient.Gender    = (Gender)patientDto.Gender;
            patient.FirstName = patientDto.FirstName;
            patient.LastName  = patientDto.LastName;

            patientData.Update(patient);
            patientData.Commit();

            return(NoContent());
        }