static void TestGetMarketDetail() { MarketDetail marketDetail = Api.GetMarketDetail("ethbtc"); if (marketDetail == null) { Console.WriteLine("GetMarketDetail Failed!"); return; } Console.WriteLine("GetMarketDetail Succeed:"); Console.WriteLine(" symbol = {0}", marketDetail.symbol); Console.WriteLine(" ts = {0}", marketDetail.ts); Console.WriteLine(" amount = {0}", marketDetail.amount); Console.WriteLine(" vol = {0}", marketDetail.vol); Console.WriteLine(" high = {0}", marketDetail.high); Console.WriteLine(" low = {0}", marketDetail.low); Console.WriteLine(" rose = {0}", marketDetail.rose); Console.WriteLine(" close = {0}", marketDetail.close); Console.WriteLine(" open = {0}", marketDetail.open); }
public async Task <ActionResult> GetMarketDetails(int id) { //pass the id.Get request to api to get market details var searchDetails = context.MarketSearch.Where(s => s.Id == id).FirstOrDefault(); var exdeatils = context.MarketDetail.Where(i => i.SearchId == searchDetails.Id).FirstOrDefault(); MarketDetailsViewModel detailsModel = new MarketDetailsViewModel { MarketSearch = new MarketSearch(), MarketDetail = new MarketDetail() }; detailsModel.MarketSearch = searchDetails; using (var client = new HttpClient()) { var url = @"http://search.ams.usda.gov/farmersmarkets/v1/data.svc/mktDetail?id="; url = url + searchDetails.SearchId; var response = await client.GetAsync(url); if (response.IsSuccessStatusCode) { var stringDetails = await response.Content.ReadAsStringAsync(); var json = JObject.Parse(stringDetails); var j_mAddress = json["marketdetails"]["Address"].ToObject <string>(); var j_mGoogleLink = json["marketdetails"]["GoogleLink"].ToObject <string>(); //get Lat and Long from google link string getLatAndLong = j_mGoogleLink.Substring(j_mGoogleLink.LastIndexOf('/') + 4); string[] splitLink = getLatAndLong.Split('('); if (splitLink.Length > 0) { string val = splitLink[0]; int indexPercent = val.IndexOf("%"); string g_Latitude = val.Substring(0, indexPercent); int lastPercent20 = val.LastIndexOf("%20"); string subLongitude = val.Substring(0, lastPercent20); int firstPercent20 = subLongitude.IndexOf("-"); string g_Longitude = subLongitude.Substring(firstPercent20); var j_mProducts = json["marketdetails"]["Products"].ToObject <string>(); //keep schedule but remove everything to the right of AND including semicolon var j_mSchedule = json["marketdetails"]["Schedule"].ToObject <string>(); var subSchedule = j_mSchedule.Substring(0, j_mSchedule.IndexOf(';')); MarketDetail marketDetails = new MarketDetail(); marketDetails.SearchId = searchDetails.Id; marketDetails.Address = j_mAddress; marketDetails.Latitude = g_Latitude; marketDetails.Longitude = g_Longitude; marketDetails.Products = j_mProducts; marketDetails.Schedule = subSchedule; context.MarketDetail.Add(marketDetails); context.SaveChanges(); detailsModel.MarketDetail = marketDetails; } } } return(View(detailsModel)); }
public ActionResult SaveMarket(int id) { MarketDetail SaveTrip = context.MarketDetail.Find(id); return(View(SaveTrip)); }