コード例 #1
0
        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());
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        public IEnumerable <Book> GetAllBooks()
        {
            var bookData = new BookData();

            return(bookData.GetBooks());
        }
コード例 #7
0
        public IEnumerable <Book> GroupBy()
        {
            var bookData = new BookData();

            return(bookData.GroupByG(bookData.GetBooks()));
        }
コード例 #8
0
        public IEnumerable <Book> SortBook()
        {
            var bookData = new BookData();

            return(bookData.SortBooks(bookData.GetBooks()));
        }
コード例 #9
0
 public IHttpActionResult GetBooks()
 {
     return(Ok(BookData.GetBooks()));
 }
コード例 #10
0
 public Book GetByIsbn(string isbn)
 {
     return(BookData.GetBooks().Where(b => b.Isbn == isbn).FirstOrDefault());
 }
コード例 #11
0
 public Book GetById(int id)
 {
     return(BookData.GetBooks().Where(b => b.Id == id).FirstOrDefault());
 }
コード例 #12
0
 public IEnumerable <Book> GetAll()
 {
     return(BookData.GetBooks());
 }
コード例 #13
0
 public MainPage()
 {
     this.InitializeComponent();
     Books = BookData.GetBooks();
 }