public async Task<ProductModel> EditProductAsync(ProductModel product) { using (var client = new HttpClient()) { var values = HelperMethods.CreateKeyValuePairsFromReflection(product); client.DefaultRequestHeaders.Authorization = HelperMethods.CreateAuthorizationHeader(_apiKey); var content = new FormUrlEncodedContent(values); HttpResponseMessage response = await client.PutAsync(BaseRequestUri, content); return await GetProductByIdAsync(product.ProdID); } }
public async Task<ProductModel> CreateProductAsync(ProductModel product) { using (var client = new HttpClient()) { var values = HelperMethods.CreateKeyValuePairsFromReflection(product); client.DefaultRequestHeaders.Authorization = HelperMethods.CreateAuthorizationHeader(_apiKey); var content = new FormUrlEncodedContent(values); HttpResponseMessage response = await client.PostAsync(BaseRequestUri, content); string responseString = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject<ProductModel>(responseString); } }