Example #1
0
        public IActionResult Create([FromBody] Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            library.AddBook(book);

            return(CreatedAtAction("Get", new { id = book.Id }, book));
        }
        public RedirectToActionResult AddToLibrary(int id)
        {
            ISession session = _provider.GetRequiredService <IHttpContextAccessor>()?.HttpContext.Session;

            string libraryId = session.GetString("LibraryId") ?? Guid.NewGuid().ToString();

            session.SetString("LibraryId", libraryId);

            _library.AddBook(libraryId, _books.GetBook(id));

            return(RedirectToAction("BooksList"));
        }
Example #3
0
        public IActionResult AddBooks([FromBody] Book value)
        {
            bool solution = ibk.AddBook(value);

            if (solution == false)
            {
                return(BadRequest());
            }
            else
            {
                return(Ok());
            }
        }
Example #4
0
        private void newToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            BookForm bookForm = new BookForm(new Book());

            if (bookForm.ShowDialog() == DialogResult.OK)
            {
                _library.AddBook(bookForm.Book);
                // for LibraryM
                bookBindingSource.DataSource = _library.Books;
                // for Library
                bookBindingSource.ResetBindings(false);

                bookBox.SelectedIndex = bookBox.Items.Count - 1;
            }
        }
        public IActionResult AddBook([FromBodyAttribute] Book book)
        {
            // Ensure we have content in the body
            if (book == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NoContent));
            }

            // Attempt to add the Book in the collection
            if (_library.AddBook(book))
            {
                return(new StatusCodeResult((int)HttpStatusCode.Created));
            }
            else
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotModified));
            }
        }
 private void button_Click(object sender, RoutedEventArgs e)
 {
     proxy.AddBook("CSharp", "C. Sharp", 2000);
 }