예제 #1
0
        private async Task RefreshProducts()
        {
            using (var client = new HttpClient())
            {
                FilterViewModel filter = new FilterViewModel(_filter);
                filter.clear();
                URLBuilder url = new URLBuilder(filter, "/api//Product/");
                url.URL += "&ShowMyOffers=true";
                var request = new HttpRequestMessage()
                {
                    RequestUri = new Uri(url.URL),
                    Method     = HttpMethod.Get
                };
                request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _authenticationUser.UserId.ToString(), _authenticationUser.Password))));
                var response = await client.SendAsync(request);

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

                List <ProductDto> result = JsonConvert.DeserializeObject <List <ProductDto> >(contents);
                Products.Clear();
                foreach (ProductDto p in result)
                {
                    ProductWrapper product = p.createProduct();
                    Products.Add(product);
                }
            }
        }
예제 #2
0
        public async Task UpdateOffer()
        {
            using (var client = new HttpClient())
            {
                FilterViewModel filter = new FilterViewModel(_filter);
                filter.clear();
                filter.Name     = _selectedOffer.Product.Name;
                filter.SellerId = _authenticationUser.UserId;
                filter.Stock    = "1";
                URLBuilder url     = new URLBuilder(filter, "/api//Product/");
                var        request = new HttpRequestMessage()
                {
                    RequestUri = new Uri(url.URL),
                    Method     = HttpMethod.Get
                };
                request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _authenticationUser.UserId.ToString(), _authenticationUser.Password))));
                var response = await client.SendAsync(request);

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

                List <ProductDto> result = JsonConvert.DeserializeObject <List <ProductDto> >(contents);
                if (result.Count() == 1)
                {
                    if (result.First().Stock < _selectedOffer.Amount)
                    {
                        ErrorString = (string)Application.Current.FindResource("StockError");
                        return;
                    }
                }
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                SellOfferDto content = createOffer(_selectedOffer);
                var          json    = Newtonsoft.Json.JsonConvert.SerializeObject(content);
                url = new URLBuilder(controler);
                var request2 = new HttpRequestMessage()
                {
                    RequestUri = new Uri(url.URL),
                    Method     = HttpMethod.Put,
                    Content    = new StringContent(json,
                                                   Encoding.UTF8,
                                                   "application/json")
                };
                request2.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _authenticationUser.UserId.ToString(), _authenticationUser.Password))));
                var response2 = await client.SendAsync(request2);

                if (!response2.IsSuccessStatusCode)
                {
                    ErrorString = (string)Application.Current.FindResource("InvalidBuyOfferError");
                    return;
                }
            }
            await Load();

            ErrorString = null;
        }