Esempio n. 1
0
        public static Customer Update(Customer c)
        {
            BookRegContext context = new BookRegContext();

            context.Entry(c).State = EntityState.Modified;

            context.SaveChanges();

            return(c);
        }
Esempio n. 2
0
        public static Customer AddCustomer(Customer c)
        {
            BookRegContext context = new BookRegContext();

            context.Customer.Add(c);

            context.SaveChanges();

            return(c);
        }
        public static List <Customer> GetCustomers()
        {
            BookRegContext context = new BookRegContext();

            //SELECT * FROM Customers
            List <Customer> allCustomers = (from c in context.Customer
                                            select c).ToList();

            return(allCustomers);
        }
Esempio n. 4
0
        public static void AddBook(Book b)
        {
            //Database context
            BookRegContext context = new BookRegContext();

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

            //Executes all pending Insert/Update/Delete
            context.SaveChanges();
        }
Esempio n. 5
0
        public static void DeleteCustomer(Customer c)
        {
            var context = new BookRegContext();

            //context.Customer.Attach(c);
            //context.Customer.Remove(c);

            //Alternative
            context.Entry(c).State =
                System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
        public static void DeleteCustomer(Customer c)
        {
            BookRegContext context = new BookRegContext();

            //Telling Entity Framework (EF) that the customer
            //exists, and we want it removed from the DB
            //context.Customer.Attach(c);
            //context.Customer.Remove(c);

            //ALTERNATIVE
            context.Entry(c).State = EntityState.Deleted;

            context.SaveChanges();
        }
Esempio n. 7
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
            //LINQ Query Syntax
            //List<Book> allBooks =
            //    (from b in context.Book
            //        //where b.Price <= 50
            //    select b).ToList();

            //LINQ Method Syntax
            List <Book> allBooks =
                context.Book.ToList();

            return(allBooks);
        }