public async Task <bool> UpdateUser(User user) { _builder.AddToPath(_settings.UserPath); using var message = _builder .HttpMethod(HttpMethod.Put).AddToPath("/" + user.Id). Content(new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json")) .GetHttpMessage(); return(await GetResponseStringAsync(message) != null); }
public async Task <bool> DeleteCart(string username) { var _builder = new HttpRequestBuilder(_settings.BaseAddress).AddToPath(_settings.BasketPath); using var message = _builder.AddToPath(username) .HttpMethod(HttpMethod.Delete) .GetHttpMessage(); var response = await GetResponseStringAsync(message); return(response != null); }
public async Task <IEnumerable <Product> > GetProductByPage(int page) { if (_builder != null) { _builder.Dispose(); } using (_builder = new HttpRequestBuilder(_settings.BaseAddress)) { _builder.AddToPath(_settings.CatalogPath); using var message = _builder.AddQueryString("page", page.ToString()) .HttpMethod(HttpMethod.Get) .GetHttpMessage(); return(await GetResponseAsync <IEnumerable <Product> >(message)); } }
public async Task <bool> UpdateProduct(Product product) { if (_builder != null) { _builder.Dispose(); } using (_builder = new HttpRequestBuilder(_settings.BaseAddress)) { _builder.AddToPath(_settings.CatalogPath); using var message = _builder.HttpMethod(HttpMethod.Put).Content(new StringContent(JsonConvert.SerializeObject(product), Encoding.UTF8, "application/json")) .GetHttpMessage(); var response = await GetResponseAsync <Product>(message); return(response != null); } }
public UsersApi(IApiSettings settings, IHttpClientFactory factory) : base(factory) { _settings = settings; _builder = new HttpRequestBuilder(_settings.BaseAddress); _builder.AddToPath(_settings.UsersPath); }
public CatalogApi(IHttpClientFactory factory, IApiSettings settings) : base(factory) { _settings = settings; _builder = new HttpRequestBuilder(_settings.BaseAddress); _builder.AddToPath(_settings.CatalogPath); }