using BeatifulPlace.App.Dtos;
using BeautifulPlaces.App.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace BeatifulPlace.App.Services
{
public class ApiService
{
public HttpClientService HttpClientService { get; set; }
public JsonService JsonService { get; set; }
public string ApiUri { get; set; } = "http://beautifulplacesapi.azurewebsites.net/";
public ApiService()
{
HttpClientService = new HttpClientService();
JsonService = new JsonService();
}
async public Task<BaseResponse<List<PlaceDto>>> GetPlaces()
{
BaseResponse<List<PlaceDto>> response;
try
{
HttpResponseMessage result =
await HttpClientService.GetAsync($"{ApiUri}api/Places");
if (result.IsSuccessStatusCode)
{
var serializedResponse = await JsonService.GetSerializedResponse<List<PlaceDto>>(result);
response = new BaseResponse<List<PlaceDto>> { Response = serializedResponse, HttpResponse = result };
}
else
{
response = new BaseResponse<List<PlaceDto>> { HttpResponse = result };
}
}
catch (Exception ex)
{
response = new BaseResponse<List<PlaceDto>> {
HttpResponse = new HttpResponseMessage {
StatusCode = System.Net.HttpStatusCode.ExpectationFailed } };
}
return response;
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.