Exemplo n.º 1
0
 public static Author GetAuthorsById(int id)
 {
     using (var ctx = new BooksEntities())
     {
         Author author = ctx.Authors.Find(id);
         return author;
     }
 }
Exemplo n.º 2
0
 public static List<Author> GetAllAuthors()
 {
     using (var ctx = new BooksEntities())
     {
         List<Author> allAuthors = ctx.Authors.ToList();
         return allAuthors;
     }
     
     
 }
Exemplo n.º 3
0
 public static void DeleteAuthor(int authorId)
 {
     using (var ctx = new BooksEntities())
     {
         Author authorToDelete = ctx.Authors.Find(authorId);
         if (authorToDelete != null)
         {
             ctx.Authors.Remove(authorToDelete);
             ctx.SaveChanges();
         }
         
     }
 }
Exemplo n.º 4
0
        public static void UpdateAuthorName(int authorId, string newFirstName, string newLastName)
        {
            //Author authorToUpdate = GetAuthorsById(authorId);

            using (var ctx = new BooksEntities())
            {
                Author authorToUpdate = ctx.Authors.Find(authorId);

                authorToUpdate.FirstName = newFirstName;
                authorToUpdate.LastName = newLastName;

                ctx.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public static int AddNewAuthor(string newAuthorFirstName, string newAuthorLastName)
        {
            using (var ctx = new BooksEntities())
            {
                Author newAuthor = new Author();

                newAuthor.FirstName = newAuthorFirstName;
                newAuthor.LastName = newAuthorLastName;

                ctx.Authors.Add(newAuthor);

                ctx.SaveChanges();
                return newAuthor.AuthorID;
            }
        }