public IEnumerable <Book> EditBook() { var data = Request.Content.ReadAsStringAsync(); var newBook = JObject.Parse(data.Result); var bookData = new BookData(); var books = bookData.GetBooks(); var a = newBook["author"].ToString(); var t = newBook["title"].ToString(); var isEd = true; if (!books.Exists(b => b.Author.Contains(a) && b.Title.Contains(t))) { isEd = false; throw new HttpResponseException(HttpStatusCode.BadRequest); } var booktoEdit = books.Find(b => b.Title.Equals(t) && b.Author.Equals(a)); booktoEdit.Price = newBook["price"].ToString(); booktoEdit.Date = newBook["date"].ToString(); booktoEdit.Genre = newBook["genre"].ToString(); booktoEdit.Description = newBook["description"].ToString(); bookData.Save(books); return(bookData.GetBooks()); }
public IEnumerable <Book> RemoveBook() { var data = Request.Content.ReadAsStringAsync(); var newBook = JObject.Parse(data.Result); var bookData = new BookData(); var books = bookData.GetBooks(); var a = newBook["author"].ToString().Trim(); var t = newBook["title"].ToString().Trim(); if (!books.Exists(b => b.Author.Contains(a) && b.Title.Contains(t))) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var book = books.Find(x => x.Author.Equals(a) && x.Title.Equals(t)); books.Remove(book); bookData.Save(books); return(bookData.GetBooks()); }
public IEnumerable <Book> AddBook() { var data = Request.Content.ReadAsStringAsync(); var newBook = JObject.Parse(data.Result); var bookData = new BookData(); var books = bookData.GetBooks(); var book = new Book(); book.Author = newBook["author"].ToString(); book.Title = newBook["title"].ToString(); var isAdd = true; if (books.Exists(b => b.Author.Contains(book.Author) && b.Title.Contains(book.Title))) { isAdd = false; throw new HttpResponseException(HttpStatusCode.BadRequest); } books.Add(book); bookData.Save(books); return(bookData.GetBooks()); }
public ActionResult Index() { const string key = "books"; var books = CacheEngine.Get <List <Book> >(key); if (books == null) { books = BookData.GetBooks(); CacheEngine.Add(key, books); } ViewBag.books = books; return(View()); }
static void Main(string[] args) { const string key = "books"; var books = CacheEngine.Get <List <Book> >(key); if (books == null) { books = BookData.GetBooks(); CacheEngine.Add(key, books); } var cachedBooks = CacheEngine.Get <List <Book> >(key); foreach (var book in books) { System.Console.WriteLine(book.Name); } System.Console.ReadKey(); }
public IEnumerable <Book> GetAllBooks() { var bookData = new BookData(); return(bookData.GetBooks()); }
public IEnumerable <Book> GroupBy() { var bookData = new BookData(); return(bookData.GroupByG(bookData.GetBooks())); }
public IEnumerable <Book> SortBook() { var bookData = new BookData(); return(bookData.SortBooks(bookData.GetBooks())); }
public IHttpActionResult GetBooks() { return(Ok(BookData.GetBooks())); }
public Book GetByIsbn(string isbn) { return(BookData.GetBooks().Where(b => b.Isbn == isbn).FirstOrDefault()); }
public Book GetById(int id) { return(BookData.GetBooks().Where(b => b.Id == id).FirstOrDefault()); }
public IEnumerable <Book> GetAll() { return(BookData.GetBooks()); }
public MainPage() { this.InitializeComponent(); Books = BookData.GetBooks(); }