public ActionResult <Book> Post([FromBody] Book value)
 {
     try
     {
         Book   newBook = _manager.Add(value);
         string uri     = Url.RouteUrl(RouteData.Values) + "/" + newBook.Id;
         return(Created(uri, newBook));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemplo n.º 2
0
        public void TestItAll()
        // We cannot control the execution order of test methods.
        // unless we have only one test method ...
        {
            BooksManager manager = new BooksManager();

            List <Book> allBooks = manager.GetAll();

            Assert.AreEqual(3, allBooks.Count);

            Book book = manager.GetById(1);

            Assert.AreEqual("C# is nice", book.Title);

            Assert.IsNull(manager.GetById(100));

            Book newBook = new Book {
                Title = "Android Programing", Price = 17.85
            };
            Book addedBook = manager.Add(newBook);

            Assert.AreEqual(4, addedBook.Id);
            Assert.AreEqual(4, manager.GetAll().Count);

            Book updates = new Book {
                Title = "Android Programming", Price = 18.1
            };
            Book updatedBook = manager.Update(3, updates);

            Assert.AreEqual("Android Programming", updatedBook.Title);

            Assert.IsNull(manager.Update(100, updates));

            Book deletedBook = manager.Delete(3);

            Assert.AreEqual("Android Programming", deletedBook.Title);
            Assert.AreEqual(3, manager.GetAll().Count);

            Assert.IsNull(manager.Delete(100));
        }
Exemplo n.º 3
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            try
            {
                ImageFileUpload.SaveAs(Server.MapPath("~/Librarian/Books/BookImages") + Path.GetFileName(ImageFileUpload.FileName));
                String GetImagePath = "~/Librarian/Books/BookImages" + Path.GetFileName(ImageFileUpload.FileName);

                Book _Book = new Book();
                _Book.Name           = txtBookName.Text;
                _Book.AuthorName     = txtBookAuthorName.Text;
                _Book.AvailableQty   = Convert.ToDecimal(txtBookQty.Text);
                _Book.Images         = GetImagePath;
                _Book.CategoriesCode = CategoryDropDownList.SelectedValue.ToString();

                decimal AlreadyExistBook = _BooksManager.AlreadyExistBook(_Book);
                if (AlreadyExistBook >= 1)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('This Book Already Exist!!..');", true);
                }
                else
                {
                    int successAdd = _BooksManager.Add(_Book);
                    if (successAdd > 0)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Saved Book Successefully!!..');", true);
                        Clear();
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Failed saved!!..');", true);
                    }
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + ex.Message + "');", true);
            }
        }
Exemplo n.º 4
0
 public Book Post([FromBody] Book value)
 {
     return(_manager.Add(value));
 }