public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto) { userForRegisterDto.Username = userForRegisterDto.Username.ToLower(); userForRegisterDto.EmailAddress = userForRegisterDto.EmailAddress.ToLower(); if (await _repo.UserExists(userForRegisterDto.Username)) { return(BadRequest("Username already exists")); } var userToCreate = new User { Username = userForRegisterDto.Username, EmailAddress = userForRegisterDto.EmailAddress }; var createUser = await _repo.Register(userToCreate, userForRegisterDto.Password); return(StatusCode(201)); }
public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto) { userForRegisterDto.Username = userForRegisterDto.Username.ToLower(); if (await _repo.UserExists(userForRegisterDto.Username)) { return(BadRequest("Username already exists")); } var userToCreate = _mapper.Map <User>(userForRegisterDto); var createUser = await _repo.Register(userToCreate, userForRegisterDto.Password); var userToReturn = _mapper.Map <UserForDetailedDto>(createUser); return(CreatedAtRoute("GetUser", new { Controller = "Users", id = createUser.Id }, userToReturn)); }
public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto) { userForRegisterDto.Username = userForRegisterDto.Username.ToLower(); if (await respository.UserExists(userForRegisterDto.Username)) { return(BadRequest("Użytkownik o takej nazwie już istnieje !")); } var userToCreate = mapper.Map <User>(userForRegisterDto); User createdUser = await respository.Register(userToCreate, userForRegisterDto.Password); var userToReturn = mapper.Map <UserForDetailedDto>(createdUser); return(CreatedAtRoute("GetUser", new { controller = "Users", Id = createdUser.Id }, userToReturn)); }
public async Task <IActionResult> Register(UserForRegistration userForRegistration) { userForRegistration.Username = userForRegistration.Username.ToLower(); if (await _repo.UserExists(userForRegistration.Username)) { return(BadRequest("User already exists")); } var userToCreate = new User { UserName = userForRegistration.Username }; await _repo.Register(userToCreate, userForRegistration.Password); return(StatusCode(201)); }
public async Task <IActionResult> Register(UserForRegisterDto userForRegister) { //Vaidate request //if (!ModelState.IsValid) // return BadRequest(ModelState); userForRegister.Username = userForRegister.Username.ToLower(); if (await _repo.UserExists(userForRegister.Username)) { return(BadRequest("username already exists!!")); } var userToCreate = _mapper.Map <User>(userForRegister); var createdUser = await _repo.Register(userToCreate, userForRegister.Password); var userToReturn = _mapper.Map <UerForDetailedDto>(createdUser); //return CreatedAtRoute() return(CreatedAtRoute("GetUser", new { Controller = "Users", id = createdUser.Id }, userToReturn)); }
public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto) { //validate username 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)); }