Example #1
0
 public List <Book> GetBooksList()
 {
     using (BookDbExpressEntities entities = new BookDbExpressEntities())
     {
         return(entities.Books.ToList());
     }
 }
Example #2
0
 public void AddBook(string name)
 {
     using (BookDbExpressEntities entities = new BookDbExpressEntities())
     {
         Book book = new Book {
             BookName = name
         };
         entities.Books.Add(book);
         entities.SaveChanges();
     }
 }
Example #3
0
        public Book GetBookById(string id)
        {
            try
            {
                int bookId = Convert.ToInt32(id);

                using (BookDbExpressEntities entities = new BookDbExpressEntities())
                {
                    return(entities.Books.SingleOrDefault(book => book.Id == bookId));
                }
            }
            catch
            {
                throw new FaultException("Something went wrong");
            }
        }
Example #4
0
        public void DeleteBook(string id)
        {
            try
            {
                int bookId = Convert.ToInt32(id);

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