public static List <Customer> GetCustomers()
        {
            BookRegContext  context      = new BookRegContext();
            List <Customer> allCustomers = context.Customer.ToList();

            return(allCustomers);
        }
        public static Customer Update(Customer cus)
        {
            BookRegContext context = new BookRegContext();

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

            return(cus);
        }
        public static Customer AddCustomer(Customer cus)
        {
            BookRegContext context = new BookRegContext();

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

            return(cus);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
        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();
        }