public void Add(BookCommand bookCommand) { Book book = Book.FromBookCommand(bookCommand); _booksValidator.Validate(book); _booksRepository.Add(book); }
public async Task <BookModel> Handle(AddBookCommand request, CancellationToken cancellationToken) { var book = _mapper.Map <Book>(request.Book); var img = request.Book.Image.ToCoverImage(); _logger.LogInformation($"Adding new book. Payload: {JsonConvert.SerializeObject(book)}. With image size: {img.Content.Length} bytes."); return(_mapper.Map <BookModel>(await _repository.Add(book, img))); }
public async Task <IActionResult> Post([FromBody] Book value) { if (value == null) { return(BadRequest("Book is empty")); } await booksRepository.Add(value); return(Ok("Book created")); }
public IActionResult Create([FromBody] Book newBook) { if (newBook == null) { return(BadRequest()); } _booksRepository.Add(newBook); return(CreatedAtRoute("GetBookById", new { bookId = newBook.Id }, newBook)); }
public async Task <IActionResult> Post(Book book) { await _booksRepository.Add(book); if (book == null) { return(NotFound("The Book record could not be found")); } return(CreatedAtAction(nameof(Get), new { ISBN = book.ISBN }, book)); }
public int Add(string title, string author, int year) { var id = repository.Add(title, author, year); if (id > 0) { logger.LogDebug($"Clean cache: {GetAllCacheKey}"); cache.Remove(GetAllCacheKey); } return(id); }
public async Task AddBookCommand_should_successfully_store_correct_book() { // Arrange var file = new byte[] { 1, 2, 3 }; await using var ms = new MemoryStream(file); var contentType = "image/jpeg"; var newBook = new NewBookModel { Author = "Correct", Title = "Correct", Description = "Correct", Price = 1, Image = Helpers.CreateTestFormFile(ms, contentType) }; var book = _mapper.Map <Book>(newBook); book.CoverImage = new CoverImage { Content = file, ContentType = contentType }; A.CallTo(() => _repository.Add(A <Book> .Ignored, A <CoverImage> .Ignored)).Returns(book); // Act var result = await _handler.Handle(new AddBookCommand(newBook), default); // Assert A.CallTo(() => _repository.Add(A <Book> .Ignored, A <CoverImage> .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(newBook.Title, result.Title); Assert.Equal(newBook.Author, result.Author); Assert.Equal(newBook.Description, result.Description); Assert.Equal(newBook.Price, result.Price); Assert.Equal($"/books/{result.Id}/image", result.ImageUrl); }
public async Task <IActionResult> Post([FromBody] Book book) { try { if (book != null) { await _booksRepository.Add(book); } return(Ok(book)); } catch (Exception c) { return(BadRequest($"Not found book with id {book.BookId}")); } }
public IActionResult Post(CreateOrUpdateBookModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var title = model.Title; var author = model.Author; var year = model.Year; var id = books.Add(title, author, year); if (id <= 0) { return(StatusCode(500)); } return(CreatedAtAction("Get", new { id, title })); }
public IActionResult Create([FromBody] BooksViewModel books) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Books _newbook = Mapper.Map <BooksViewModel, Books>(books); _newbook.CreateDate = DateTime.Now; _booksRepository.Add(_newbook); _booksRepository.Commit(); books = Mapper.Map <Books, BooksViewModel>(_newbook); CreatedAtRouteResult result = CreatedAtRoute("GetBooks", new { controller = "Books", id = books.Id }, books); return(result); }
public IActionResult Add(BookCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = ProccessUpoadedFile(model); Book book = new Book { Title = model.Title, Author = model.Author, Year = model.Year, ISBN = model.ISBN, Location = model.Location, NumberOfCopies = model.NumberOfCopies, ImageUrl = uniqueFileName }; _booksRepository.Add(book); //Book newbook = _booksRepository.Add(model); return(RedirectToAction("details", new { id = book.Id })); } return(View()); }
public void Add(Book book) { repository.Add(book); }
public void AddAssetsBooks(BooksAttribute item) { _assetsBooksRep.Add(item); }
public async Task AddAndSave(Models.Books book) { _booksRepo.Add(book); await _booksRepo.Save(); }
public void AddBook(Books book) { booksRepository.Add(book); }
public virtual IActionResult Post([FromBody] Book book) { book.ID = Guid.NewGuid(); booksRepository.Add(book); return(this.Created($"/api/[controller]/{book.ID}", book)); }
public void Post([FromBody] Book book) { _booksRepository.Add(book); }
public async Task Add(Book book) { await _booksRepository.Add(book); }
public async Task <ActionResult <Book> > AddBook(Book entity) { await _booksRepository.Add(entity); return(Ok(entity)); }
// POST: api/Books public HttpResponseMessage Post([FromBody] Book value) { int id = _booksRepository.Add(value); return(Request.CreateResponse <int>(HttpStatusCode.Created, id)); }