public async Task <IActionResult> CreateUser([FromBody] CreateUserViewModel createUserViewModel)
        {
            if (!_roleService.Exist(createUserViewModel.RoleId) || !_affiliateService.Exist(createUserViewModel.AffiliateId))
            {
                return(NotFound());
            }

            if (_userService.GetByUsername(createUserViewModel.Email) != null)
            {
                ModelState.AddModelError(nameof(createUserViewModel.Email), "This email is already taken");
                return(BadRequest(ModelState));
            }

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

            var userDTO = UserMapper.AddUserViewModelToDTO(createUserViewModel);

            await _userService.CreateUser(userDTO);

            return(Ok(ModelState));
        }
        public async Task <IActionResult> UpdatePassword(string id, [FromBody] PasswordUserViewModel passwordUserViewModel)
        {
            if (!_userService.Exist(id))
            {
                return(NotFound());
            }

            if (!await _userService.CheckPassword(passwordUserViewModel.Id, passwordUserViewModel.CurrentPassword))
            {
                ModelState.AddModelError(nameof(passwordUserViewModel.CurrentPassword), "The password you provided is wrong");
                return(BadRequest(ModelState));
            }

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

            var userDTO = UserMapper.PasswordUserViewModelToDTO(passwordUserViewModel);

            await _userService.UpdatePassword(userDTO);

            return(NoContent());
        }
Exemplo n.º 3
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));
        }