Exemplo n.º 1
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.º 2
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();
            }
        }
Exemplo n.º 3
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;
            }
        }