public IActionResult CreateCrawlDetail(string name, DateTime crawlDate, bool haveTheme, string Theme) { Crawl c = new Crawl { name = name, datetime = crawlDate, Theme = Theme }; c.UserID = User.FindFirstValue(ClaimTypes.NameIdentifier); //Auto join creator c.crawlUser.Add(new CrawlUser { crawl = c, usersID = c.UserID }); Barcrawl bc = new Barcrawl(); List <Barcrawl> listBarcrawl = new List <Barcrawl>(); List <Bar> bar = PossibleBars; foreach (Bar b in bar) { if (!db.Bar.Where(x => x.BarId == b.BarId).Any()) { db.Bar.Add(b); } c.barCrawl.Add(new Barcrawl { BarId = b.BarId, CrawlID = c.CrawlID, } ); } string[] bob = bar[0].Location.Split(','); string qwer = bob[1] + bob[2]; string qwert = qwer.Replace("]", ""); string qwerty = qwert.Replace("\"", ""); string[] qwertyu = qwerty.Split(' '); c.Location = qwertyu[2] + ", " + qwertyu[3]; db.Crawl.Add(c); db.SaveChanges(); string id = c.CrawlID.ToString(); return(RedirectToAction("CrawlDetails", new { id = id })); }
public List <Bar> getCrawlBars(Bar start, int radius, int numBars) { Random rand = new Random(); Bar point = start; List <Bar> crawlList = new List <Bar>(); crawlList.Add(point); // Get all valid bars while (crawlList.Count < numBars) { HttpWebRequest request = WebRequest.CreateHttp($"https://api.yelp.com/v3/businesses/search?term=bars&location={point.Location}&radius={radius}"); request.Headers.Add("Authorization", "Bearer 5AZ1TMhzZzb52DbbAMkydLPjNRSURY3x-DtC2o7qDjNTa2n96PSxuLZMmQoBy3WtX5q4EWUh4KQWVG1GG_nq_x2YLEssXjh5WF5kYw8E_VPmyRVMRfDHLwOYM0bXXXYx"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader rd = new StreamReader(response.GetResponseStream()); string ApiText = rd.ReadToEnd(); JToken tokens = JToken.Parse(ApiText); List <JToken> ts = tokens["businesses"].ToList(); List <Bar> possibleList = new List <Bar>(); foreach (JToken t in ts) { Bar b = new Bar(t); possibleList.Add(b); } // RNG choose a close by bar, add to list int index = rand.Next(possibleList.Count); point = possibleList[index]; // Add only if it's not already on the list bool dup = false; foreach (Bar x in crawlList) { if (x.BarId == point.BarId) { dup = true; } } if (!dup) { crawlList.Add(point); } } Bars = crawlList; //for saving the crawl Barcrawl crawl = new Barcrawl(); return(crawlList); }