示例#1
0
        public virtual async Task <ApiResult <UserReturnDto> > Create(UserDto userDto, CancellationToken cancellationToken)
        {
            _logger.LogError("متد Create فراخوانی شد");

            var user = new User
            {
                Birthday    = userDto.Birthday,
                FullName    = userDto.FullName.ToLower(),
                Gender      = userDto.Gender,
                UserName    = userDto.UserName.ToLower(),
                Email       = _security.EmailChecker(userDto.Email),
                PhoneNumber = userDto.PhoneNumber.Fa2En()
            };

            var result = await _userManager.CreateAsync(user, userDto.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(result.ToString()));
            }

            var roleResult = await _userManager.AddToRoleAsync(user, "Member");

            if (!roleResult.Succeeded)
            {
                return(BadRequest());
            }

            return(_mapper.Map <UserReturnDto>(user));
        }