예제 #1
0
        public static List <Customer> GetCustomers()
        {
            BookRegContext  context      = new BookRegContext();
            List <Customer> allCustomers = context.Customer.ToList();

            return(allCustomers);
        }
예제 #2
0
        public static Customer Update(Customer cus)
        {
            BookRegContext context = new BookRegContext();

            context.Entry(cus).State = EntityState.Modified;
            context.SaveChanges();

            return(cus);
        }
예제 #3
0
        public static Customer AddCustomer(Customer cus)
        {
            BookRegContext context = new BookRegContext();

            context.Customer.Add(cus);
            context.SaveChanges();

            return(cus);
        }
예제 #4
0
        public static Book AddBook(Book boo)
        {
            BookRegContext context = new BookRegContext();

            // Create insert query
            // Adds insert to a list of pending queries
            context.Book.Add(boo);

            // Executes all pending queries
            context.SaveChanges();

            return(boo);
        }
예제 #5
0
        public static List <Book> GetAllBooks()
        {
            // Create a context object to connect and query the DB
            BookRegContext context = new BookRegContext();

            // Use LINQ to query the database using the context
            //List<Book> allBooks = (
            //    from boo in context.Book
            //    select boo ).ToList();

            List <Book> allBooks = context.Book.ToList();

            return(allBooks);
        }
예제 #6
0
        public static void DeleteCustomer(Customer cus)
        {
            BookRegContext context = new BookRegContext();

            // Saying cus exists in the DB
            context.Customer.Attach(cus);
            // Removing cus from the DB
            context.Customer.Remove(cus);

            // Alternative
            // context.Entry(cus).State = EntityState.Deleted;

            context.SaveChanges();
        }