/// <summary> /// Receives user input, makes call to Police API and returns the appropriate crimes /// </summary> /// <param name="address"></param> /// <param name="date"></param> /// <param name="type"></param> /// <returns></returns> public List <Crime> Map(string address, string date, string type) { //Call to ReturnLatLong method to get the coords var latLng = ReturnLatLng(address); //Parse the responce var crimesLocation = new Geoposition(double.Parse(latLng.First().Value), double.Parse(latLng.ElementAt(1).Value)); DateTime crimesDate = DateTime.ParseExact(date, "MMMM yyyy", CultureInfo.InvariantCulture); //Initialize a Police client object. var policeClient = new PoliceUkClient(); //Calls police API and retrieves the crimes var crimes = policeClient.StreetLevelCrimes(crimesLocation, crimesDate).Crimes.ToList(); //If category is specified, filter the crimes if (!type.Equals("All crime") && !type.Equals("")) { var typeFormat2 = type.ToLower().Replace(" ", "-"); crimes = crimes.Where(x => x.Category == typeFormat2).ToList(); } //Format the category of each crime to be readable foreach (var crime in crimes) { crime.Category = crime.Category.ToUpper().First() + crime.Category.Remove(0, 1).Replace("-", " "); if (crime.OutcomeStatus is null) { crime.OutcomeStatus = new PoliceUk.Entities.OutcomeStatus { Date = "Unknown", Category = "Unknown" } } ; } crimes = SumCrimeTypes(crimes); return(crimes); }
public List <string> ReturnTypeDd() { var typesToString = new List <string>(); PoliceUkClient client = new PoliceUkClient(); List <PoliceUk.Entities.Category> categories = client.CrimeCategories(DateTime.UtcNow).ToList(); foreach (var category in categories) { typesToString.Add(category.Name); } return(typesToString); }