public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new User { UserName = model.Email, Email = model.Email, Password = model.Password }; HttpClient client = httpClient.InitializeClient(_jwtApiBaseUri); client.DefaultRequestHeaders.Add("JWTAppKey", _config["JWTApp:Key"]); client.DefaultRequestHeaders.Add("JWTAppSecret", _config["JWTApp:Secret"]); var content = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("api/authorize/register", content); var result = await response.Content.ReadAsStringAsync(); string error = string.Empty; if (response.IsSuccessStatusCode) { //await signInManager.SignInAsync(user, isPersistent:false); return(RedirectToAction("login", "account")); //return Content("User successfully registered!"); } else { if (!string.IsNullOrEmpty(result)) { error = JsonConvert.DeserializeObject(result).ToString(); } else { error = response.ReasonPhrase; } } ModelState.AddModelError(string.Empty, "Registration failed " + error); } return(View(model)); }
public async Task <IActionResult> Index() { List <User> dto = new List <User>(); HttpClient client = _userAPI.InitializeClient("http://localhost:5002"); HttpResponseMessage res = await client.GetAsync("api/v1/users"); //Checking the response is successful or not which is sent using HttpClient if (res.IsSuccessStatusCode) { //Storing the response details recieved from web api var result = res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list dto = JsonConvert.DeserializeObject <List <User> >(result); } //returning the employee list to view return(View(dto)); }