public async Task <IActionResult> PostUser([FromBody] CreateUserDto request)
        {
            var user = await userManager.CreateAsync(userFactory, request.Email, request.DisplayName, request.Password);

            var response = new UserCreatedDto {
                Id = user.Id, PictureUrl = user.PictureUrl()
            };

            return(Ok(response));
        }
Exemple #2
0
        public async Task <IActionResult> PostUser([FromBody] CreateUserDto request)
        {
            var user = await userManager.CreateAsync(userFactory, request.ToValues());

            var response = new UserCreatedDto {
                Id = user.Id
            };

            return(Ok(response));
        }
        public async Task <UserCreatedDto> Create(UserCreatedDto createdUser)
        {
            var validationResult = _userValidator.Validate(createdUser);

            if (!validationResult.IsValid)
            {
                throw new Exception(validationResult.ToString());
            }
            else
            {
                var findedUser = await _userManager.FindByEmailAsync(createdUser.Email);

                if (findedUser == null)
                {
                    var newUser = _mapper.Map <UserCreatedDto, User>(createdUser);
                    var result  = await _userManager.CreateAsync(newUser, createdUser.Password);

                    var confirmEmailToken = await _userManager.GenerateEmailConfirmationTokenAsync(newUser);

                    string validToken = await _tokenService.CreateValidToken(confirmEmailToken);

                    string url     = $"{_configuration["AppUrl"]}/confirmemail?userid={newUser.Id}&token={validToken}";
                    string content = $"<h1>Welcome to TMAS </h1><p>Please confirm your email by  <a href='{url}'>Clicking here</a></p>";

                    EmailOptions email = new EmailOptions {
                        Email   = newUser.Email,
                        Content = content,
                        Subject = "Confirm your email",
                    };

                    await _emailService.SendEmailAsync(email);

                    return(createdUser);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #4
0
        public async Task <UserCreatedDto> AddUser(UserDto user)
        {
            UserCreatedDto userCreatedDtoResponse = null;

            // Assign the URL
            _restClient.BaseUrl = new Uri($"{BaseUrl}/users");

            // Wait until to get a response
            _restClient.Timeout = -1;

            // Assign the Method Type
            var request = new RestRequest(Method.POST);

            // Assign the Headers
            request.AddHeader("Authorization", TokenDto.Token);
            request.AddHeader("Content-Type", "application/json");

            // Assign the Body
            var content = JsonConvert.SerializeObject(user);

            request.AddParameter("application/json", content, ParameterType.RequestBody);

            // Execute the Call
            IRestResponse response = await _restClient.ExecuteAsync(request);

            // Checking the response is successful or not which is sent using HttpClient
            if (response.StatusCode == HttpStatusCode.Created)
            {
                // Storing the content response recieved from web api
                var responseContent = response.Content;

                //Deserializing the response recieved from web api and storing into the Employee list
                userCreatedDtoResponse = JsonConvert.DeserializeObject <UserCreatedDto>(responseContent);
            }

            return(userCreatedDtoResponse);
        }
        public async Task <ActionResult <UserCreatedDto> > Registrate([FromBody] UserCreatedDto model)
        {
            var createResult = await _userService.Create(model);

            return(Ok(createResult));
        }