Ejemplo n.º 1
0
        public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto)
        {
            // validate request
            userForRegisterDto.Username = userForRegisterDto.Username.ToLower();

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

            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));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto)
        {
            //TODO: Validate Request
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //Convert username to lowercase
            userForRegisterDto.Username = userForRegisterDto.Username.ToLower();

            if (await _repo.UserExist(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);
            return(Ok());
        }