private HttpContent CreateApiRequest(CreateUserApiModel user) { return(new StringContent( JsonConvert.SerializeObject(user), Encoding.UTF8, JsonContentType)); }
public IHttpActionResult Post( CreateUserApiModel userToCreate) { if (string.IsNullOrEmpty(userToCreate.Login)) { return(this.BadRequest("Login is required")); } if (string.IsNullOrEmpty(userToCreate.Password)) { return(this.BadRequest("Password is required")); } if (string.IsNullOrEmpty(userToCreate.CountryId)) { return(this.BadRequest("CountryIso is required")); } this.userService.Add( new Services.CreateUserModel { BirthDate = userToCreate.BirthDate, CountryIsoCode3 = userToCreate.CountryId, FirstName = userToCreate.FirstName, LastName = userToCreate.LastName, Login = userToCreate.Login, Password = userToCreate.Password }); return(this.Ok()); }
public async Task <IActionResult> Register(CreateUserApiModel model) { try { if (ModelState.IsValid == false) { return(ValidationProblem()); } var userResult = await _userService.CreateIdentityUserAsync(new UpsertUserModel { Email = model.Email, Password = model.Password, Username = model.Username }); if (userResult.IsValid == false) { return(BadRequest(userResult.Errors)); } var tokenResult = await _userService.GetTokensAsync(new TokenRequest { UserValue = userResult.ResultObj.Email, Identifier = userResult.ResultObj.Id, ClientId = HttpContext.Connection.LocalIpAddress.ToString() }); return(Ok(tokenResult)); } catch (Exception ex) { return(BadRequest(AppConstants.GenericErrorMsg)); } }
public async Task <bool> CreateUser(CreateUserApiModel user) { using (var httpClient = new HttpClient()) { return(await httpClient .PostAsync( CreateResourceUri("users"), CreateApiRequest(user)) .ContinueWith(task => task.Result.IsSuccessStatusCode)); } }
public async Task <IHttpActionResult> Post(CreateUserApiModel model) { if (ModelState.IsValid && model != null) { var user = Mapper.Map <User>(model); user.Enabled = true; user.EmailConfirmed = true; var result = await this.userManager.CreateAsync(user, model.Password); if (result.Succeeded) { if ((await this.userManager.AddToRoleAsync(user.Id, "user")).Succeeded) { return(this.Ok(new ApiResponse(200, Mapper.Map <UserApiModel>(user)))); } } return(this.InternalServerError(new ApiResponse(500, Mapper.Map <UserApiModel>(user)))); } return(this.BadRequest(new ApiResponse(400, model))); }