Пример #1
0
 public void AddBook(string name)
 {
     using (var bookContext = new BookContext())
     {
         Book book = new Book { BookName = name };
         bookContext.Books.Add(book);
         bookContext.SaveChanges();
     }
 }
Пример #2
0
        public void DeleteBook(string id)
        {
            try
            {
                int bookId = Convert.ToInt32(id);

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