Ejemplo n.º 1
0
        public async Task <ActionResult <Book> > GetBook(int id, String authName, String bookName, bool sort)
        {
            List <Book> books = null;//lista que ira retornar os books

            //pesquisa um book por id
            if (id != null)
            {
                Book book = new BookDAO().searchById(id);
                if (book != null)
                {
                    return(Ok(book));             // new JsonResult(book)
                }
            }

            //pesquisa books pelo nome do autor
            if (authName != null && authName != "")
            {
                books = new BookDAO().searchByAuthName(authName);

                //caso exista retorna uma lista de livros ordenada ou nao
                if (books != null && books.Count() > 0)
                {
                    return(sort ? new JsonResult(this.sortList(books))  :  new JsonResult(books));
                }
            }

            //pesquisa books pelo nome do livro
            if (bookName != null && bookName != "")
            {
                books = new BookDAO().searchByBookName(bookName);

                //caso exista retorna uma lista de livros ordenada ou nao
                if (books != null && books.Count() > 0)
                {
                    return(sort ? new JsonResult(this.sortList(books)) : new JsonResult(books));
                }
            }

            //caso nao encontre nada
            return(NotFound(new JsonResult(
                                "nada econtrado com os parametros id: " + id
                                + " authName: " + authName
                                + " bookName: " + bookName)));
        }
Ejemplo n.º 2
0
        public JsonResult Gets(string key = "", string author = "", string category = "", string publisher = "", int publishYear = 0, int status = 2, int page = 1, int pageSize = 5)
        {
            try
            {
                List <Book> data     = dao.Gets(key, author, category, publisher, publishYear, status, page, pageSize);
                int         totalRow = dao.Count(key, category, publisher, publishYear, status);

                return(Json(new
                {
                    data = data,
                    totalRow = totalRow
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new
                {
                    data = DBNull.Value.ToString()
                }, JsonRequestBehavior.AllowGet));
            }
        }