public IHttpActionResult Get(long id) { if (id == 0) { return(BadRequest("Invalid ProductId.")); } var url = ConfigurationManager.AppSettings["DataUrl"]; if (string.IsNullOrEmpty(url)) { return(BadRequest("Invalid URI.")); } var response = httpClient.GetAsync(url).Result; if (!response.IsSuccessStatusCode) { return(BadRequest("Product not found.")); } ; var jsonString = response.Content.ReadAsStringAsync().Result; JObject jsonResponse = JObject.Parse(jsonString); var productName = jsonResponse["product"]["item"]["product_description"]["title"].ToString(); var dl = new RetailDl(); var data = dl.getData(); if (!data.Any()) { return(BadRequest("Price not found.")); } var price = data.FirstOrDefault(p => p.ProductId == id); if (productName == null || price == null) { return(BadRequest("Product not found.")); } var product = new Product { Id = id, Name = productName, CurrentPrice = new Price { Value = price.Value, CurrencyCode = price.CurrencyCode } }; return(Ok(product)); }
public IHttpActionResult Put(long id, [FromBody] decimal price) { if (id == 0) { return(BadRequest("Invalid ProductId")); } var dl = new RetailDl(); dl.updateData(id, price); return(Ok()); }