public void AddDemoBooks() { var jr = new Author("Joanne", "Rowling"); var leo = new Author("Leo", "Tolstoy"); var bs = new Author("Brandon", "Sanderson"); var rm = new Author("Robert", "Martin"); _authorsRepository.AddAuthor(jr); _authorsRepository.AddAuthor(leo); _authorsRepository.AddAuthor(bs); _authorsRepository.AddAuthor(rm); _booksRepository.AddBook(new Book("Harry Potter", 455, new DateTime(2005, 1, 1), "9780545010221", new[] { jr })); _booksRepository.AddBook(new Book("War and Peace", 1311, new DateTime(2011, 1, 1), "9781400079988", new[] { leo })); _booksRepository.AddBook(new Book("Mistborn", 670, new DateTime(2013, 1, 1), "9780765365439", new[] { bs }, "Tor Books")); _booksRepository.AddBook(new Book("Oathbringer", 1051, new DateTime(2017, 1, 1), "9781250297143", new[] { bs }, "Tor Books")); _booksRepository.AddBook(new Book("Clean Code", 522, new DateTime(2008, 1, 1), "9780132350884", new[] { rm }, "Эксмо")); }
public IActionResult CreateAuthor([FromBody] AuthorForCreateDto authorForCreateDto) { if (authorForCreateDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var author = _mapper.Map <Author>(authorForCreateDto); var createdAuthor = _repository.AddAuthor(author); var authorToReturn = _mapper.Map <AuthorDto>(createdAuthor); return(CreatedAtRoute("GetAuthor", new { id = authorToReturn.Id }, authorToReturn )); }
public IActionResult Post([FromBody] Author authors) { var authorsId = authorsRepository.AddAuthor(authors); return(Created($"https://localhost:5001/api/authors/{authorsId}", authors)); }
public void AddAuthor(CreateAuthorData data) { var author = new Author(data.FirstName, data.LastName); _authorsRepository.AddAuthor(author); }
public IActionResult Post([FromBody] Author author)//for creating objects { var authorId = authorsRepository.AddAuthor(author); return(Created($"https://localhost:5001/api/authors/{authorId}", author)); }
public IActionResult Post([FromBody] Author author) { var bookId = AuthorsRepository.AddAuthor(author); return Created($"https://localhost:5001/api/authors/{author}", author); }