private void InitData()
        {
            if (!publishers.IsInit)
            {
                publishers.Create(new Publisher()
                {
                    Name = "publisher1"
                });
                publishers.Create(new Publisher()
                {
                    Name = "publisher2"
                });
                publishers.IsInit = true;
            }
            if (!authors.IsInit)
            {
                authors.Create(new Author()
                {
                    Name        = "author1",
                    DateOfBirth = new DateTime(1966, 08, 15),
                    DateOfDeath = null
                });
                authors.Create(new Author()
                {
                    Name        = "author2",
                    DateOfBirth = new DateTime(1947, 11, 21),
                    DateOfDeath = new DateTime(2006, 10, 5)
                });
                authors.IsInit = true;
            }

            if (!books.IsInit)
            {
                books.Create(new Book()
                {
                    Name      = "Book1",
                    Publisher = publishers.Get(1),
                    Author    = new List <Author>()
                    {
                        authors.Get(1)
                    },
                    PublishDate = new DateTime(2010, 10, 1),
                    PageCount   = 187,
                    ISBN        = "ISBN 5-02-013850-9"
                });
                books.Create(new Book()
                {
                    Name      = "Book2",
                    Publisher = publishers.Get(1),
                    Author    = new List <Author>()
                    {
                        authors.Get(1), authors.Get(2)
                    },
                    PublishDate = new DateTime(2011, 05, 20),
                    PageCount   = 256,
                    ISBN        = "ISBN 4-13-019790-7"
                });
                books.IsInit = true;
            }
        }
        public IHttpActionResult Get([FromUri] int id)
        {
            try
            {
                //throw new ArgumentNullException("this is a test");
                Book book;
                var  booksRepository = new BooksRepository();

                if (id > 0)
                {
                    var books = booksRepository.Retrieve();
                    book = books.FirstOrDefault(p => p.BookId == id);
                    if (book == null)
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    book = booksRepository.Create();
                }

                return(Ok(book));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public async Task <ActionResult <Books> > Create([FromBody] Books books)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var result = await _booksRepository.Create(books);

            return(CreatedAtAction("Create", new { id = result }, books));
        }
Example #4
0
        // NOTE Create Request
        internal Book Create(Book newBook)
        {
            Book createdBook = _repo.Create(newBook);

            return(createdBook);
        }
 public Book Create(Book newBook)
 {
     return(_repo.Create(newBook));
 }
Example #6
0
 public Bookers Create(Bookers newVid)
 {
     return(_repo.Create(newVid));
 }
Example #7
0
 internal Book Create(Book newBook)
 {
     return(_repo.Create(newBook));
 }