Example #1
0
        public async Task <IActionResult> Register(Dtos.UserForRegisterDto userForRegisterDto)
        {
            // Validate Request

            userForRegisterDto.Username = userForRegisterDto.Username.ToLower();

            if (await _repo.UserExists(userForRegisterDto.Username))
            {
                return(BadRequest("Username already exists"));
            }

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

            var createdUser = await _repo.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(Dtos.UserForRegisterDto userForRegisterDto)
        {
            // validate request
            userForRegisterDto.Username = userForRegisterDto.Username.ToLower();

            if (await _repo.UserExists(userForRegisterDto.Username))
            {
                return(BadRequest("Username already exisits"));
            }

            var userToCreate = new User
            {
                Username = userForRegisterDto.Username
            };

            var createdUser = await _repo.Register(userToCreate, userForRegisterDto.Password);

            return(StatusCode(201));
        }
Example #3
0
        public async Task <IActionResult> Register(Dtos.UserForRegisterDto userForRegisterDto)
        // object instead of username and password
        {
            //   if (!ModelState.IsValid)
            //       return BadRequest(ModelState);

            //validate request
            userForRegisterDto.Username = userForRegisterDto.Username.ToLower();

            if (await _repo.UserExists(userForRegisterDto.Username))
            {
                return(BadRequest("user already exists"));
            }


            var userToCreate = new User {
                Username = userForRegisterDto.Username
            };

            var createdUser = await _repo.Register(userToCreate, userForRegisterDto.Password);

            return(StatusCode(201));
        }
Example #4
0
        public async Task <IActionResult> Register([FromBody] Dtos.UserForRegisterDto userForRegisterDto)
        {
            if (!string.IsNullOrEmpty(userForRegisterDto.Username))
            {
                userForRegisterDto.Username = userForRegisterDto.Username.ToLower();
            }
            if (await _repo.UserExists(userForRegisterDto.Username))
            {
                ModelState.AddModelError("Username", "Username already exist");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userToCreate = new User
            {
                Username = userForRegisterDto.Username
            };
            var createUser = await _repo.Register(userToCreate, userForRegisterDto.Password);

            return(StatusCode(201));
        }