Ejemplo n.º 1
0
        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 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)
        {
            userForRegisterDto.username = userForRegisterDto.username.ToLower();
            if (await _repo.UserExists(userForRegisterDto.username))
            {
                return(BadRequest("this user is exsit"));
            }

            var userToCreate = new User {
                Username = userForRegisterDto.username
            };
            var CreatedUser = _repo.Register(userToCreate, userForRegisterDto.password);

            return(StatusCode(201));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Register([FromBody] UserForRegister userforregister)
        {
            return(BadRequest("sa"));

            if (await _auth.UserExists(userforregister.username))
            {
                ModelState.AddModelError("duplicate user", "user already exists");
            }
            if (ModelState.IsValid)
            {
                var user = await _auth.Register(userforregister);

                if (user == null)
                {
                    return(BadRequest("unable to create user"));
                }
                var UserToReturn = _mapper.Map <UserDetailDTO>(user);

                return(CreatedAtRoute("getuser", new { Controller = "users", userid = user.id }, UserToReturn));
            }
            return(BadRequest(ModelState));
        }