public async Task <IActionResult> Register([FromBody] UserForRegisterDto userForRegisterDto)
        {
            //validate request
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            userForRegisterDto.Username = userForRegisterDto.Username.ToLower();
            if (await _repo.UserExists(userForRegisterDto.Username))
            {
                return(BadRequest("Username already exists"));
            }
            var userToCreate = new User
            {
                UserName = userForRegisterDto.Username,
            };
            var createdUser = await _repo.Register(userToCreate, userForRegisterDto.Password);

            return(StatusCode(201));
        }
Beispiel #2
0
        public async Task <IActionResult> Register([FromBody] UserForRegisterDto userForRegisterDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            userForRegisterDto.username = userForRegisterDto.username.ToLower();

            if (await _repo.UserExist(userForRegisterDto.username))
            {
                return(BadRequest("UserName already exist"));
            }

            var userdetails = new User
            {
                Username = userForRegisterDto.username
            };

            var CreatedUser = await _repo.Register(userdetails, userForRegisterDto.username);

            return(StatusCode(201));
        }
Beispiel #3
0
        public async Task <IActionResult> Register(UserForRegisterDTO userDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            userDto.UserName = userDto.UserName.ToLower();

            if (await _repo.UserExists(userDto.UserName))
            {
                return(BadRequest("UserName already exists"));
            }

            var userToCreate = _mapper.Map <User>(userDto);

            var createduser = await _repo.Register(userToCreate, userDto.PassWord);

            var userToReturn = _mapper.Map <UserForDetailsDto>(createduser);

            return(CreatedAtRoute("GetUser", new { Controller = "Users", id = createduser.Id }, userToReturn));
        }