public Author AddAuthor(Author author)
 {
     author.AuthorId = dataSource.Authors.Count > 0
         ? (dataSource.Authors[dataSource.Authors.Count - 1].AuthorId + 1)
         : 1;
     dataSource.Authors.Add(author);
     return author;
 }
        public void UpdateAuthor(Author author)
        {
            var foundAuthor = dataSource.Authors.FirstOrDefault(e => e.AuthorId == author.AuthorId);
            if (foundAuthor == null)
            {
                return;
            }

            foundAuthor.FirstName = author.FirstName;
            foundAuthor.LastName = author.LastName;
        }
Example #3
0
        public JsonResult UpdateAuthor(Author author)
        {
            if (!ModelState.IsValid)
            {
                return Json(new
                {
                    Result = "ERROR",
                    Message = "Form is not valid! " +
                              "Please correct it and try again."
                });
            }

            authorRepository.UpdateAuthor(author);
            return Json(new { Result = "OK" });
        }
Example #4
0
        public JsonResult CreateAuthor(Author author)
        {
            if (!ModelState.IsValid)
            {
                return Json(new
                {
                    Result = "ERROR",
                    Message = "Form is not valid! " +
                              "Please correct it and try again."
                });
            }

            var addeAuthor = authorRepository.AddAuthor(author);
            return Json(new { Result = "OK", Record = addeAuthor });
        }
        public void CanAddAndGetAuthorsOfBook()
        {
            var newAuthor = new Author
            {
                BookId = 2,
                FirstName = "Renée",
                LastName = "French"
            };

            authorRepository.AddAuthor(newAuthor);
            var authorList = authorRepository.GetAuthorsOfBook(2);
            var savedAuthor = authorList.Single(x => x.AuthorId.Equals(9));

            Assert.AreEqual(authorList.Count, 3);
            Assert.AreSame(newAuthor, savedAuthor);
        }