public async Task<string> RegisterUser(UserLoginModel loginModel, string authenticationToken) { if (!loginModel.IsValid()) { return "invalid_model"; } using (var client = new HttpClient()) { var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("Username", loginModel.Username), new KeyValuePair<string, string>("Password", loginModel.Password) }); client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + authenticationToken); var postResponse = await client.PostAsync("http://resz.azurewebsites.net/User/createUser", formContent); postResponse.EnsureSuccessStatusCode(); return await postResponse.Content.ReadAsStringAsync(); } }
async partial void btnRegister_TouchUpInside(UIButton sender) { lblRegisterFormFeedback.Text = "contacting API, please wait ..."; lblRegisterFormFeedback.TextColor = UIColor.Blue; UserLoginModel model = new UserLoginModel(txtRegisterUsername.Text, txtRegisterPassword.Text); if (!model.IsValid()) { lblRegisterFormFeedback.Text = "please fill in your details"; lblRegisterFormFeedback.TextColor = UIColor.Red; return; } ServiceWrapper serviceWrapper = new ServiceWrapper(); TokenModel tokenModel = await serviceWrapper.GetAuthorizationTokenData(); string authenticationResult = await serviceWrapper.RegisterUser(model, tokenModel.access_token); lblRegisterFormFeedback.Text = authenticationResult; lblRegisterFormFeedback.TextColor = UIColor.Blue; }