public ActionResult <string> CreateClient([Required, FromBody] AltSourceNewClientDto input) { AccountsLib.Client newClient; try { UserInputValidation.ValidateUsername(input.Username); UserInputValidation.ValidateName(input.FirstName); UserInputValidation.ValidateName(input.LastName); var userInfo = User.GetUserInfo(); var username = userInfo.AccountsUsername; using (var session = Logic.Login(Repository, username)) { newClient = Logic.CreateClient(session, input.Username, input.FirstName, input.LastName); } } catch (AccountsLibException ex) { return(new ActionFailureResult(new ApiResponse(500, ex.Message))); } return(newClient?.ClientId); }
public IActionResult Put([BindRequired, FromBody] AltSourceNewUserDto input) { try { UserInputValidation.ValidateUsername(input.Username); UserInputValidation.ValidatePassword(input.Password); UserInputValidation.ValidateName(input.FirstName); UserInputValidation.ValidateName(input.LastName); UserInputValidation.ValidateAddress(input.Address); var encodedAddress = HtmlEncoder.Default.Encode(input.Address); // ReSharper disable once UnusedVariable var result = Users.CreateAltSourceUser(_userManager, input.Username, input.Password, input.FirstName, input.LastName, encodedAddress, false) .Result; if (!result.Succeeded) { return(BadRequest(result.CompileErrorMessage())); } } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public async Task <string> CreateClient(string username, string firstName, string lastName) { UserInputValidation.ValidateUsername(username); UserInputValidation.ValidateName(firstName); UserInputValidation.ValidateName(lastName); var newClient = new AltSourceNewClientDto(username, firstName, lastName); var jsonNewUser = JsonConvert.SerializeObject(newClient); var content = new StringContent(jsonNewUser, Encoding.UTF8, "application/json"); var response = await this.InvokeApiAsync(Post, @"api/admin/create/client", content); var newClientId = await response.TryGetResponseContent(); return(newClientId); }