Ejemplo n.º 1
0
        public async Task <AdvertResponse> Create(AdvertModel model)
        {
            var advertApiModel = new AdvertModel(); //TODO:AutoMapper

            var jsonModel = JsonSerializer.Serialize(advertApiModel);
            var response  = await _httpClient.PutAsync(_httpClient.BaseAddress, new StringContent(jsonModel));

            var responseJson = await response.Content.ReadAsStringAsync();

            var createAdvertResponse = JsonSerializer.Deserialize <CreateAdvertResponse>(responseJson);
            var advertResponse       = new AdvertResponse(); //TODO:AutoMapper;

            return(advertResponse);
        }
Ejemplo n.º 2
0
        public async Task<AdvertResponse> Create(CreateAdvertModel model)
        {
            AdvertModel advertApiModel = _mapper.Map<AdvertModel>(model);

            string jsonModel = JsonConvert.SerializeObject(advertApiModel);

            HttpResponseMessage response = await _client.PostAsync(
                new Uri($"{_baseAddress}/create"),
                new StringContent(jsonModel, Encoding.UTF8, "application/json")
            );

            string createAdvertResponse = await response.Content.ReadAsStringAsync();
            AdvertResponse jsonResponse = JsonConvert.DeserializeObject<AdvertResponse>(createAdvertResponse);

            AdvertResponse advertResponse = _mapper.Map<AdvertResponse>(jsonResponse);

            return advertResponse;
        }