public IActionResult Post([FromBody] Book myNewBook) { var book = _booksService.Add(myNewBook); if (book == null) { return(BadRequest()); } return(CreatedAtAction("Get", new { Id = myNewBook.Id }, myNewBook)); }
public async Task <IActionResult> Create([Bind("Id,Title,Author,Isbn")] Book book) { if (ModelState.IsValid) { await _booksService.Add(book); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public async Task <ActionResult> Post([FromBody] BooksDTO entity) { try { return(Ok(await _booksService.Add(entity))); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }
public async Task <ActionResult> Post([FromBody] Book book) { var response = await _booksService.Add(book.ToDomainObject()); if (response.Status == Status.ValidationError) { return(BadRequest(response.ValidationResult.ToModelStateDictionary())); } return(StatusCode((int)HttpStatusCode.Created)); }
public async Task Post_NoValidationError_ReturnsCreatedStatusCode() { // Arrange var model = new Contract.Book { ISBN = "9780132350884", Author = "Robert C. Martin", Title = "Clean Code: A Handbook of Agile Software Craftsmanship", PageCount = 464 }; _booksService.Add(Arg.Any <Book>()).Returns(new OperationResult <Book> { Status = Status.Success }); // Act var result = await _booksController.Post(model) as StatusCodeResult; // Assert Assert.AreEqual((int)HttpStatusCode.Created, result.StatusCode); }
public IActionResult CompleteNewBook(EditBookModel model) { if (!HandleErrorsBeforeCompletingBook(model)) { return(View("NewBook", model)); } // Add book var book = new Book(model.BookName, LanguagesService.Get(model.BookLanguageID), model.BookDescription); book = BooksService.Add(book); return(RedirectToAction("Book", new { id = book.ID })); }
public async Task <IActionResult> Add(Book book) { await _booksService.Add(book); return(Ok(book)); }
public void Post([FromBody] Book book) { service.Add(book); }
public async Task <ActionResult> Create(BookEditModel model) { return(Ok(await booksService.Add(new Book(model)))); }
public async Task <Book> Post([FromBody] Book item) { return(await _booksService.Add(item)); }
public Book Add(BookToCreate bookToCreate) { return(booksService.Add(bookToCreate)); }
public int PostBook([FromBody] Book book) { var bookId = _booksService.Add(book); return(bookId); }