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);
 }
示例#2
0
        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);
        }
示例#3
0
 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));
     }
 }
示例#4
0
        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);
            }
        }
示例#5
0
 public UsersApi(IApiSettings settings, IHttpClientFactory factory) : base(factory)
 {
     _settings = settings;
     _builder  = new HttpRequestBuilder(_settings.BaseAddress);
     _builder.AddToPath(_settings.UsersPath);
 }
示例#6
0
 public CatalogApi(IHttpClientFactory factory, IApiSettings settings) : base(factory)
 {
     _settings = settings;
     _builder  = new HttpRequestBuilder(_settings.BaseAddress);
     _builder.AddToPath(_settings.CatalogPath);
 }