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);
        }
Esempio n. 3
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. 4
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();
        }