Пример #1
0
        public IActionResult Post([FromBody] Book myNewBook)
        {
            var book = _booksService.Add(myNewBook);

            if (book == null)
            {
                return(BadRequest());
            }
            return(CreatedAtAction("Get", new { Id = myNewBook.Id }, myNewBook));
        }
Пример #2
0
        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));
        }
Пример #3
0
 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);
        }
Пример #6
0
        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 }));
        }
Пример #7
0
        public async Task <IActionResult> Add(Book book)
        {
            await _booksService.Add(book);

            return(Ok(book));
        }
Пример #8
0
 public void Post([FromBody] Book book)
 {
     service.Add(book);
 }
Пример #9
0
 public async Task <ActionResult> Create(BookEditModel model)
 {
     return(Ok(await booksService.Add(new Book(model))));
 }
Пример #10
0
 public async Task <Book> Post([FromBody] Book item)
 {
     return(await _booksService.Add(item));
 }
Пример #11
0
 public Book Add(BookToCreate bookToCreate)
 {
     return(booksService.Add(bookToCreate));
 }
Пример #12
0
        public int PostBook([FromBody] Book book)
        {
            var bookId = _booksService.Add(book);

            return(bookId);
        }