Ejemplo n.º 1
0
        public static Author GetAuthorById(int id)
        {
            using (var ctx = new BooksEntities())
            {
                Author author = ctx.Authors.Find(id);

                return author;
            }
        }
Ejemplo n.º 2
0
        public static List<Author> GettAllAuthors()
        {
            using (var ctx = new BooksEntities())
            {
                List<Author> allAuthors = ctx.Authors.ToList();

                return allAuthors;
            }
        }
Ejemplo 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();
                }
            }
        }
Ejemplo n.º 4
0
        public static void UpdateAuthorName(int authorId, string newFirstName, string newLastName)
        {
            //Author authorToUpdate = GetAuthorById(authorId);

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

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

                ctx.SaveChanges();
            }
        }
Ejemplo 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;
            }
        }