public void AddAuthor(Author author)
 {
     using (Context)
     {
         try
         {
             Context.Authors.Add(author);
             Context.SaveChanges();
         }
         catch
         {
             throw;
         }
     }
 }
        public ActionResult Create(string firstName, string lastName)
        {
            if (String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(lastName))
            {
                throw new ArgumentOutOfRangeException();
            }

            var authorRepo = new AuthorRepository();
            var authorToAdd = new Author();

            authorToAdd.FirstName = firstName;
            authorToAdd.LastName = lastName;

            authorRepo.AddAuthor(authorToAdd);

            return RedirectToAction("Index");
        }
        public void UpdateAuthor(Author author)
        {
            using (Context)
            {
                try
                {
                    //var authorToUpdate = Context.Authors.Find(author.Id);
                    var authorToUpdate = (from a in Context.Authors where a.Id == author.Id select a).FirstOrDefault();

                    if (authorToUpdate != null)
                    {
                        authorToUpdate.Books = author.Books;
                        authorToUpdate.FirstName = author.FirstName;
                        authorToUpdate.LastName = author.LastName;
                        Context.SaveChanges();
                    }
                    else
                        throw new ArgumentException("Object Id not found!");
                }
                catch
                {

                    throw;
                }
            }
        }