//</JSON methods> /// <summary> /// Name: grabQuery /// Takes in query parameters and outputs a list of /// all films matching it /// </summary> /// <param name="searchInput"></param> /// <param name="sortBy"></param> /// <returns></returns> public String grabQuery(string searchInput, string sortBy) { dynamic jsonContent = JsonConverter(searchInput); filmDates fDS = new filmDates(); filmDate tempFilmDate = new filmDate(); string tempString = string.Empty; //If a movie is input that does not have any entries, no //display_title property will exist for them, and this will //result in an error. This conditional checks for that. if ((Convert.ToString(jsonContent)).Contains("display_title") && (searchInput != "")) { //Loops through "stuff" and adds values to fDS for (int i = 0; i < jsonContent.results.Count; i++) { tempFilmDate = new filmDate(Convert.ToString(jsonContent.results[i].display_title), Convert.ToString(jsonContent.results[i].summary_short), convertDate(Convert.ToString(jsonContent.results[i].opening_date))); fDS.addFilm(tempFilmDate); } //call sort to see what this list looks like when sorted switch (sortBy) { case "Alphabetically": fDS.sortAlphabetically(); break; case "Newest First": fDS.sortAscending(); break; case "Oldest First": fDS.sortDescending(); break; } foreach (filmDate f in fDS) { tempString = (tempString + f + "\r\n\r\n"); } } return(tempString); }
//created new compare method to compare two dates using datetime's CompareTo call. //If value is less than zero, f1 isn ealier than f2. //If value is zero, than f1 and f2 are the same date. //Else, f1 is later than f2. private static int compareDates(filmDate f1, filmDate f2) { return(f1.getReleaseDate().CompareTo(f2.getReleaseDate())); }
private static int compareNames(filmDate f1, filmDate f2) { return(f1.getName().CompareTo(f2.getName())); }
public Boolean addFilm(filmDate input) { fList.Add(input); return(true); }