예제 #1
0
        public async Task <IActionResult> Register(UserForRegsiterDto userForRegsiterDto)
        {
            userForRegsiterDto.Username = userForRegsiterDto.Username.ToLower();
            if (await _db.UserRepository.UserExists(userForRegsiterDto.Username))
            {
                return(BadRequest(new ReturnMessage()
                {
                    status = false,
                    title = "خطا",
                    message = "نام کاربری وجود ندارد",
                }));
            }

            var userTocreated = new User
            {
                Username    = userForRegsiterDto.Username,
                Name        = userForRegsiterDto.Name,
                PhoneNumber = userForRegsiterDto.PhoneNumber,
                Address     = "",
                City        = "",
                DateOfBirth = DateTime.Now,
                Gender      = "",
                IsActive    = true,
                Status      = true,
            };
            var CreatedUser = await _authService.Register(userTocreated, userForRegsiterDto.Password);

            return(StatusCode(201));
        }
예제 #2
0
        public async Task <IActionResult> Register([FromBody] UserForRegsiterDto userForRegisterDto)
        {
            //validation
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            userForRegisterDto.UserName = userForRegisterDto.UserName.ToLower();
            if (await _repo.UserExists(userForRegisterDto.UserName))
            {
                return(BadRequest("Username is already taken "));
            }
            var newUser = new User
            {
                Username = userForRegisterDto.UserName
            };
            var creatUser = await _repo.Register(newUser, userForRegisterDto.Password);

            return(StatusCode(201));
        }