Exemplo n.º 1
0
        public async Task <ActionResult> Create(PatientViewModel patientViewModel)
        {
            if (ModelState.IsValid)
            {
                var checkingUser = UserManager.FindByEmail(patientViewModel.Email);

                if (checkingUser == null)
                {
                    Patient patient = PatientViewModel.ToPatient(patientViewModel);
                    patient.Doctors.AddRange(db.Doctors.ToList().Where
                                                 (doctor => patientViewModel.DoctorsIds.Contains(doctor.Id)));

                    await CreateUser(patientViewModel);

                    ImageWorker imagePathGetter = new ImageWorker();
                    patient.ImageUrl = imagePathGetter.GetImageStringPath(patientViewModel.UserImage);
                    SaveImage(patientViewModel, patient);

                    db.Patients.Add(patient);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            patientViewModel.Doctors           = db.Doctors.ToList();
            patientViewModel.AttendingDoctorId = 1;
            return(View(patientViewModel));
        }