Beispiel #1
0
 public List<Book> GetBooksList()
 {
     using (BookContext context = new BookContext())
     {
         return context.Books.ToList();
     }
 }
Beispiel #2
0
 public void AddBook(string title)
 {
     using (BookContext context = new BookContext())
     {
         Book book = new Book { BookTitle = title };
         context.Books.Add(book);
         context.SaveChanges();
     }
 }
Beispiel #3
0
        public Book GetBookById(string id)
        {
            try
            {
                int bookId = Convert.ToInt32(id);

                using (BookContext context = new BookContext())
                {
                    return context.Books.SingleOrDefault(book => book.ID == bookId);
                }
            }
            catch
            {
                throw new FaultException("Something went wrong");
            }
        }
Beispiel #4
0
        public void UpdateBook(string id, string title)
        {
            try
            {
                int bookId = Convert.ToInt32(id);

                using (BookContext context = new BookContext())
                {
                    Book book = context.Books.SingleOrDefault(b => b.ID == bookId);
                    book.BookTitle = title;
                    context.SaveChanges();
                }
            }
            catch
            {
                throw new FaultException("Something went wrong");
            }
        }
Beispiel #5
0
        public void DeleteBook(string id)
        {
            try
            {
                int bookId = Convert.ToInt32(id);

                using (BookContext context = new BookContext())
                {
                    Book book = context.Books.SingleOrDefault(b => b.ID == bookId);
                    context.Books.Remove(book);
                    context.SaveChanges();
                }
            }
            catch
            {
                throw new FaultException("Something went wrong");
            }
        }