예제 #1
0
        public async Task <ActionResult> Create(CreatePatientViewModel patientViewModel)
        {
            if (!ModelState.IsValid)
            {
                patientViewModel.Doctors = GetDoctorListForPatientsViewModel(_doctorService.GetDoctors());
                return(View(patientViewModel));
            }
            var patient = _mapper.Map <CreatePatientViewModel, Patient>(patientViewModel);

            if (!_patientService.CheckUniqueness(patient))
            {
                ModelState.AddModelError("", "User with same UserName or Email exist!");
                patientViewModel.Doctors = GetDoctorListForPatientsViewModel(_doctorService.GetDoctors());
                return(View(patientViewModel));
            }
            await _patientService.Create(patient);

            _loggerService.Info($"{User.Identity.Name} added {patient.FirstName} {patient.LastName}");
            return(RedirectToAction("Index"));
        }