Example #1
0
        public async Task <ActionResult> Create(CreateDoctorViewModel doctorViewModel)
        {
            if (!ModelState.IsValid)
            {
                doctorViewModel.Specialities =
                    GetDoctorTypeListForPatientsViewModel(_specialityService.GetAllSpecialities());
                return(View(doctorViewModel));
            }
            var doctor = _mapper.Map <CreateDoctorViewModel, Doctor>(doctorViewModel);

            if (!_doctorService.CheckUniqueness(doctor))
            {
                ModelState.AddModelError("", "Doctor with same UserName or Email exist!");
                doctorViewModel.Specialities =
                    GetDoctorTypeListForPatientsViewModel(_specialityService.GetAllSpecialities());
                return(View(doctorViewModel));
            }
            await _doctorService.Create(doctor);

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