//Simple search function that checks if any book in the list contains any of the words in the searchstring in either title or author private IEnumerable <IBook> GetBooks(string searchString) { if (searchString == null) { return(null); } BookList returnList = new BookList(); char[] delimiters = { ' ', ',', '.', ':', '\t', '-', '+' }; string[] searchWords = searchString.Split(delimiters); foreach (Book item in books) { foreach (string word in searchWords) { if (item.Title.ToLower().Contains(word.ToLower())) { returnList.AddBook(item); break; } else if (item.Author.ToLower().Contains(word.ToLower())) { returnList.AddBook(item); break; } } } return(returnList); }
//Gets books from web, returns false if url could not be found public bool FillBookListFromWeb(string bookListAdress) { WebClient client = new WebClient(); try { string data = System.Text.Encoding.UTF8.GetString(client.DownloadData(bookListAdress)); books = JsonConvert.DeserializeObject <BookList>(data); return(true); } catch (System.Net.WebException e) { return(false); } }
public BookstoreService() { books = new BookList(); FillBookListFromWeb(BOOK_LIST_ADRESS); }