예제 #1
0
        // GET: api/Book
        /// <summary>
        ///  Retrieve a list of book items that match your criteria (All fields are optional. If no fields are given all items will be retrieved)
        /// </summary>
        /// <param name="isbn10">A unique code that specifies a book</param>
        /// <param name="isbn13">Another unique code that specifies a book</param>
        /// <param name="category">sci-fi, fantasy, non-fiction, etc.</param>
        /// <param name="publication_year">the year a book was published</param>
        public ArrayList Get(string isbn10 = null, string isbn13 = null, string category = null, int?publication_year = null)
        {
            BookPersistence bookp = new BookPersistence();

            bookp.addCallField("isbn_10", isbn10, SqlDbType.VarChar, 50);
            bookp.addCallField("isbn_13", isbn13, SqlDbType.VarChar, 50);
            bookp.addCallField("category", category, SqlDbType.VarChar, 50);
            bookp.addCallField("publication_year", publication_year, SqlDbType.Int, 4);

            return(bookp.GetAll());
        }
예제 #2
0
        // GET: api/Book/5
        /// <summary>
        ///  Retrieve the book with a specified item_id
        /// </summary>
        /// <param name="item_id">ID generated by database upon its creation</param>
        public Book Get(int item_id)
        {
            BookPersistence bookp = new BookPersistence();

            bookp.addCallField("item_id", item_id, SqlDbType.Int, 4);

            return((Book)bookp.Get());
        }
예제 #3
0
        // DELETE: api/Book/5
        /// <summary>
        ///  Delete the book with a specified item_id
        /// </summary>
        /// <param name="item_id">ID generated by database upon its creation</param>
        public HttpResponseMessage Delete(int item_id)
        {
            BookPersistence bookp = new BookPersistence();

            bookp.addCallField("item_id", item_id, SqlDbType.Int, 4);

            HttpResponseMessage ret;

            if (bookp.Delete())
            {
                ret = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                ret = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(ret);
        }
예제 #4
0
        // PUT: api/Book/5
        /// <summary>
        ///  Update an existing book with the specified item_id
        /// </summary>
        /// <param name="item_id">ID generated by database upon its creation</param>
        public HttpResponseMessage Put(int item_id, [FromBody] Book value)
        {
            BookPersistence bookp = new BookPersistence();

            bookp.addCallField("item_id", item_id, SqlDbType.Int, 4);

            bool recordExisted = bookp.Update(value);

            HttpResponseMessage response;

            if (recordExisted)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(response);
        }