public async Task <List <Rent> > GetRentsByUser(string name) { HttpResponseMessage response = await _httpService.GetClient().GetAsync($"getRentsByUser/{name}"); if (response.IsSuccessStatusCode) { return((List <Rent>)JsonSerializer.Deserialize(response.Content.ReadAsStringAsync().Result, typeof(List <Rent>))); } return(new List <Rent>()); }
public async Task <User> ValidateUser(string userName, string password) { StringContent data = new StringContent(JsonSerializer.Serialize(new UserPw(userName, password)), Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpService.GetClient().PostAsync("validateUser", data); if (response.IsSuccessStatusCode) { return((User)JsonSerializer.Deserialize(response.Content.ReadAsStringAsync().Result, typeof(User))); } throw response.StatusCode switch { HttpStatusCode.Forbidden => new Exception("Invalid password"), HttpStatusCode.NotFound => new Exception("Can't find user"), _ => new Exception("Internal Server Error") }; }
public async Task <IActionResult> Index() { var httpClient = await _httpService.GetClient("http://localhost:32771"); var response = await httpClient.GetAsync($"api/values").ConfigureAwait(false); var catsAsString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var catViewModel = JsonConvert.DeserializeObject <IEnumerable <string> >(catsAsString).ToList(); return(View(catViewModel)); }
public async Task <List <Game> > GetGamesBySearch(Search search) { var json = JsonSerializer.Serialize(search); var data = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpService.GetClient().PostAsync("getGamesBySearch/User 2", data); if (response.IsSuccessStatusCode) { return((List <Game>)JsonSerializer.Deserialize(response.Content.ReadAsStringAsync().Result, typeof(List <Game>))); } return(new List <Game>()); }