public BookListModel QueryBooks(RequestBookModel searchMessage)
        {
            var cs = "Server=localhost\\SQLEXPRESS;Database=LibraryDB;Trusted_Connection=True;";

            using var con = new SqlConnection(cs); //Using Class SqlConnection for COnnent to database
            con.Open();

            string sql = string.Format(@"SELECT Id, Name, Auther, Category, BookmarkBtn, DetailBtn FROM BookTable 
                                        WHERE(Name LIKE '%{0}%' OR Auther LIKE '%{0}%' OR Category LIKE '%{0}%')",
                                       searchMessage.text);

            using var cmd = new SqlCommand(sql, con);

            using SqlDataReader rdr = cmd.ExecuteReader();

            BookListModel output = new BookListModel();

            output.books = new List <BookModel>();

            while (rdr.Read())
            {
                output.books.Add(
                    new BookModel()
                {
                    bookId   = rdr.GetInt32(0),
                    name     = rdr.GetString(1),
                    author   = rdr.GetString(2),
                    category = rdr.GetString(3),
                    bookmark = rdr.GetBoolean(4),
                    detail   = rdr.GetBoolean(5),
                }
                    );
            }
            return(output);
        }
        public IActionResult Post([FromBody] RequestBookModel requestBookModel)
        {
            var book = bookService.Create(new Book(new Guid(),
                                                   requestBookModel.Name,
                                                   requestBookModel.Description,
                                                   requestBookModel.Isbn,
                                                   requestBookModel.AvailableQuantity));

            return(Created($"/books/{book.Id}", book));
        }
        public async Task <ActionResult <object> > UpdateBook(RequestBookModel book)
        {
            var user = await GetCurrentAuthor();

            _logger.LogTrace($"{user.UserName} try to update book {book.Id}...");
            Book bookToUpdate = _service.GetBook(book.Id);

            Mapper.Map(book, bookToUpdate);
            _service.Update(bookToUpdate);
            _logger.LogTrace($"{user.UserName} successfully update book {book.Id}");
            return(bookToUpdate);
        }
        public async Task <IActionResult> AddBook(RequestBookModel book)
        {
            var user = await GetCurrentAuthor();

            _logger.LogTrace($"AddBook method called by {user.UserName}.");
            Book newBook = Mapper.Map <RequestBookModel, Book>(book);

            newBook.AuthorId      = user.Id.ToString();
            newBook.DateOfRelease = DateTime.Now;
            _service.Create(newBook);
            _logger.LogTrace($"{user.UserName} successfully create a book!");
            return(Ok(newBook));
        }
Beispiel #5
0
        public async Task <Book> UpdateBook(RequestBookModel book)
        {
            if (book != null)
            {
                var user = await GetActualUser();

                _logger.LogTrace($"{user.Email} trying to update {book.BookId}");

                Book actualBook = _bookService.GetBook(book.BookId);
                Mapper.Map(book, actualBook);
                _bookService.Update(actualBook);
                _logger.LogTrace($"{user.Email} successfully updated {book.BookId}");
                return(actualBook);
            }

            return(null);
        }
Beispiel #6
0
        public async Task <IActionResult> AddBook(RequestBookModel book)
        {
            if (book.Content != null)
            {
                var user = await GetActualUser();

                _logger.LogTrace($"{user.Email} trying to Add new book");

                Book newBook = Mapper.Map <RequestBookModel, Book>(book);
                newBook.AuthorId    = user.Id.ToString();
                newBook.ReleaseDate = DateTime.Now;
                _bookService.Create(newBook);

                _logger.LogTrace($"{newBook.Title} was created by {user.Email}");
                return(Ok(newBook));
            }

            return(BadRequest("Error"));
        }
Beispiel #7
0
        public BookListModel SelectBooks(RequestBookModel searchMessage)
        {
            BookListModel result = _bookRepository.QueryBooks(searchMessage);

            return(result);
        }
Beispiel #8
0
        public BookListModel GetBookList(RequestBookModel searchMessage)
        {
            BookListModel result = _bookService.SelectBooks(searchMessage);

            return(result);
        }