Esempio n. 1
0
        public async Task <IActionResult> Create(DentistDataModel createDentistRequest)
        {
            if (ModelState.IsValid is false)
            {
                return(PartialView("_CreateDentist", createDentistRequest));
            }

            await _dentistService.Create(createDentistRequest);

            if (ValidOperation() is false)
            {
                return(PartialView("_CreateDentist", createDentistRequest));
            }

            var url = Url.Action("Index", "Dentist");

            return(Json(new { success = true, url, messageText = "Dentista Cadastrado com Sucesso!" }));
        }
Esempio n. 2
0
        public IActionResult CreateDentist([FromBody] CreateDentistViewModel createDentistViewModel)
        {
            if (_service.GetByUsername(createDentistViewModel.Email) != null)
            {
                ModelState.AddModelError(nameof(createDentistViewModel.Email), "This email is already taken");
                return(BadRequest(ModelState));
            }

            if (!PasswordChecker.ValidatePassword(createDentistViewModel.Password, out var message))
            {
                ModelState.AddModelError(nameof(createDentistViewModel.Password), message);
                return(BadRequest(ModelState));
            }

            var dentalDTO = DentistMapper.AddDentistViewModelToDTO(createDentistViewModel);

            _service.Create(dentalDTO);

            return(Ok(ModelState));
        }