//POST/api/authors
 public void PostAuthor(string firstName, string lastName)
 {
     Author newAuthor = new Author()
     {
         FirstName = firstName,
         LastName = lastName
     };
     this.Data.Authors.Add(newAuthor);
     this.Data.SaveChanges();
 }
 public AuthorViewModel(Author author)
 {
     Id = author.Id;
     FirstName = author.FirstName;
     LastName = author.LastName;
     Books=new List<BookViewModel>();
     foreach (var book in author.Books)
     {
        Books.Add(new BookViewModel(book));
     }
 }
 public AuthorViewModel(Author author)
 {
     this.books = new HashSet<string>();
     this.Id = author.Id;
     this.FirstName = author.FirstName;
     this.LastName = author.LastName;
     foreach (var book in author.Books)
     {
         this.BookTitles.Add(book.Title);
     }
 }
 public AuthorViewModel(Author author)
 {
     this.Id = author.Id;
     this.FirstName = author.FirstName;
     this.LastName = author.LastName;
     this.Books = new List<BookSimpleViewModel>();
     foreach (var book in author.Books)
     {
         this.Books.Add(new BookSimpleViewModel(book));
     }
 }
        public IHttpActionResult CreateAuthor([FromBody] AuthorModel authorModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest();
            }

            var author = new Author() { FirstName = authorModel.FirstName, LastName = authorModel.LastName };

            this.Data.Authors.Add(author);
            this.Data.SaveChanges();
            authorModel.Id = author.Id;
            return this.Ok(authorModel);
        }
        public IHttpActionResult PostAuthor(AddAuthorBindingModel authorBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var author = new Author(authorBindingModel.FirstName, authorBindingModel.LastName);

            context.Authors.Add(author);
            context.SaveChanges();

            var authorViewModel = new AuthorViewModel(author);

            return CreatedAtRoute("DefaultApi", new { id = authorViewModel.Id }, authorViewModel);
        }
        public IHttpActionResult CreateAuthor([FromBody]AuthorBindingModel model)
        {
            var authorsLastNames = context.Authors.Select(a => a.LastName).ToList();
            if (authorsLastNames.Contains(model.LastName))
            {
                return this.BadRequest("Author has already existed.");
            }
            var newAuthor = new Author() 
            {
                FirstName = model.FirstName,
                LastName = model.LastName
            };
            context.Authors.Add(newAuthor);
            context.SaveChanges();

            return this.Ok("Author has been created.");
        }
 public IHttpActionResult AddAuthor(AddAuthorBindingModel model)
 {
     if (model == null)
     {
         this.ModelState.AddModelError("model", "The model is empty");
     }
     if (!ModelState.IsValid)
     {
         return this.BadRequest(this.ModelState);
     }
     var author = new Author()
     {
         FirstName = model.FirstName ?? null,
         LastName = model.LastName
     };
     this.Data.Authors.Add(author);
     this.Data.SaveChanges();
     return this.CreatedAtRoute("DefaultApi", new { id = author.Id }, author);
 }
        // POST: api/Authors
        public IHttpActionResult PostAuthor([FromBody] AuthorBindingMethod model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var author = new Author()
            {
                FirstName = model.FirstName,
                LastName = model.LastName
            };
            
            db.Authors.Add(author);
            db.SaveChanges();

            var authorView = new AuthorViewModel.AuthorInfoViewModel()
            {
                FirstName = author.FirstName,
                LastName = author.LastName
            };

            return this.Ok(authorView);
        }
 public BooksAuthorViewModel(Author author)
 {
     Id = author.Id;
     FirstName = author.FirstName;
     LastName = author.LastName;
 }